1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Form Validation Won't Work In FF

Discussion in 'JavaScript' started by T0PS3O, May 5, 2005.

  1. #1
    Can someone please have a look at this code for me please? This works just fine in IE but not in FF. Can someone guide me in the right direction re: which part is the culprit please?

    <SCRIPT LANGUAGE="JAVASCRIPT">
    	<!--
    	function CheckForm() {
    			var Result;
    			Result = "";
    			//Result = Result + chkemail(document.theForm.Email.value, ", Email");
    			//Result = Result + checkDropDown("Property", ", Property");
    			
    			Result = Result + chkLength(document.theForm.ContactName.value, ", Contact Name");
    			Result = Result + chkLength(document.theForm.CompanyName.value, ", Company Name");
    			Result = Result + chkemail(document.theForm.EmailAddress.value, ", Email Address");
    			Result = Result + chkLength(document.theForm.Password.value, ", Password");
    			Result = Result + chkLength(document.theForm.ConfirmPassword.value, ", Confirm Password");
    			
    			//Result = Result + chkLength(document.theForm.YourName.value, ", Your Name");
    			//Result = Result + chkLength(document.theForm.ContactsSurname.value, ", Surname");
    			//Result = Result + checkDropDown("Sector", ", Sector");
    			//Result = Result + checkDropDown("country", ", Country");
    			
    			if (Result.length > 0) {
    				document.all['Val'].innerHTML = "Complete the fields: " + Result.substr(1);
    				return false;	
    			}
    			else
    			{
    				return true;
    			}
    		}
    	//-->
    		</SCRIPT>
    		<SCRIPT LANGUAGE="JAVASCRIPT">
    <!--
    function chkLength(str, response)
    	{
    	strReturn = "";
    	if (str.length < 1) {
    		strReturn = response;
    	}	
    	return (strReturn);	
    	}
    
    function checkDropDown(dropDownName, response)
    	{
    	strReturn = "";
    	if (document.theForm[dropDownName].selectedIndex == 0) {
    		strReturn = response;
    	}	
    	return (strReturn);	
    	}
    
    function chkemail(str, response) {
    	strReturn = "";
    	if (str.length > 0) {
    		i   = str.indexOf("@");
    		j   = str.indexOf(".",i);
    		k   = str.indexOf(",");
    		kk  = str.indexOf(" ");
    		jj  = str.lastIndexOf(".")+1;
    		len = str.length;
    		if (!((i > 0) && ( j > (i + 1)) && (k == -1) && (kk == -1) && (len - jj >= 2) && (len - jj <= 3))) {
    			strReturn = response;
    		} else {
    			if (str.length < 1) {
    				strReturn = response;
    			}
    		}	
    		} else {
    			strReturn = response;
    		}
    		return (strReturn);
    	}
    
    //-->
    		</SCRIPT>
    Code (markup):
    Form element example:

    <form action="new_go.asp" method="post" name="theForm" onSubmit="Javascript:return(CheckForm());" ID="Form2"><input class=x id=Text1 type=text size=60 name=EmailAddress>
    <input class=Button id="Submit2" type=submit value=Submit name=Submit1></form>
    Code (markup):
    Validation works great in IE, not in FF (redirects to homepage, strange!).

    Thank you!
     
    T0PS3O, May 5, 2005 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    My web developer toolbar says "Error: document.all has no properties". Google searches seem to suggest innerHTML is not part of the DOM (whatever that may mean) so FF doesn't support it. Can this be true? Ideally I'd rewrite the whole validation to server side but I'll have to give fixing this a try first...

    This is the line.

    document.all['Val'].innerHTML = "Required fields: " + Result.substr(1);
    Code (markup):
     
    T0PS3O, May 5, 2005 IP