+ Reply to Thread
Results 1 to 4 of 4

Thread: Javascript Error

  1. #1
    Tenant is offline x10Hosting Member Tenant is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    13

    Javascript Error

    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 by Tenant; 01-31-2009 at 10:00 AM.

  2. #2
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: Javascript Error

    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?
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  3. #3
    VPmase's Avatar
    VPmase is offline x10 Elder VPmase is an unknown quantity at this point
    Join Date
    Nov 2007
    Location
    Dixon, IL, USA
    Posts
    914

    Re: Javascript Error

    You are getting the value of the radio button in the wrong way. Most browsers return "undefined" with the way you are retrieving the value.

    Check this site out: http://www.webdevelopersnotes.com/ti...io_button.php3

  4. #4
    Tenant is offline x10Hosting Member Tenant is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    13

    Re: Javascript Error

    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 by Tenant; 01-31-2009 at 12:41 PM.

+ Reply to Thread

Similar Threads

  1. 500 Internal Server Error on cossacks
    By tletter in forum Free Hosting
    Replies: 1
    Last Post: 12-03-2008, 07:27 PM
  2. Internal Server Error and Errors in cpanel
    By sabinkumar in forum Free Hosting
    Replies: 7
    Last Post: 11-23-2008, 10:57 PM
  3. Error en mi host
    By roonline in forum Soporte
    Replies: 17
    Last Post: 11-14-2007, 03:28 PM
  4. 500 Internal Server Error (PHP Error?)
    By aniklaus in forum Free Hosting
    Replies: 3
    Last Post: 11-12-2007, 11:47 AM
  5. XML and Javascript
    By cuteboytm in forum Graphics & Webdesign
    Replies: 1
    Last Post: 09-21-2007, 10:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers