Javascript Error

Tenant

New Member
Messages
13
Reaction score
0
Points
0
I have been trying to get this script to work for a while now and I cant seem to find the error. I have checked all names and everything is correct. if i remove the == and only use one = it half works but does not rest its self. meaning if someone changes the radio button it stays with what happened before. If anyone can help I would be in your debt.


Code:
function varify_length()
{
    var radiobutton = document.form1.RadioGroup1.value;
            if (radiobutton == "PHONE")
            {
                var searchfield = document.form1.input3.value;
                var msg = "Please fill in all three sections of the phone number.";
                var searchlength = searchfield.length;            
            }
        else if (radio_button == "OWNER") 
            { 
                var searchfield = document.form1.input4.value;
                var msg = "Please enter at least the first three digits of the landlords last name.";
                var searchlength = searchfield.length;
            }
        else if (radio_button == "BUSINESS") 
               {
                var searchfield = document.form1.input4.value;
                var msg = "Please enter at least the first three digits of the business name.";
                var searchlength = searchfield.length;
            }
    
    
        if ( searchlength <= "2" )
        {
            alert(msg);
            return false;
        }    
}
 
Last edited:

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
Are you sure there's an error? What do you want it to do, and what's going wrong?

If it is less 2, a message pops up and it returns false.
If the searchlength is more than 2, nothing will happen. Don't you want it to return true?

In which case you need to add an 'else return true;'...


If that doesn't help you in any way, can you post the form as well or a link to an online version so we can see it in action?
 

Tenant

New Member
Messages
13
Reaction score
0
Points
0
Everything is working great now thanks for the help VPmase

This is the new code if it helps anyone
Code:
function varify_length()
{
			for (var i=0; i < document.form1.RadioGroup1.length; i++)
		   {
		   if (document.form1.RadioGroup1[i].checked)
			  {
			  var radio_val = document.form1.RadioGroup1[i].value;
			  }
		   }

		if (radio_val == "PHONE")
		{
			var searchfield = document.form1.input3.value;
			var msg = "Please fill in all three sections of the phone number.";
			var searchlength = searchfield.length;							
		}
	else if (radio_val == "OWNER") 
		{ 
			var searchfield = document.form1.input4.value;
			var msg = "Please enter at least the first three digits of the landlords last name.";
			var searchlength = searchfield.length;
		}
	else if (radio_val == "BUSINESS") 
		{
			var searchfield = document.form1.input4.value;
			var msg = "Please enter at least the first three digits of the business name.";
			var searchlength = searchfield.length;
		}
	if ( searchlength <= "2" )
			{
				alert(msg);
				return false;
			}
}
 
Last edited:
Top