Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Firefox form checking

Options
  • 22-06-2005 4:20pm
    #1
    Closed Accounts Posts: 8,478 ✭✭✭


    Lew

    I have some javascript checking form values for blank entries and so on, but it's not working with Firefox :/ I could use the processing PHP page to check the values that were just sent in, but I think its better to have the info displayed immediately on the entry page rather than having to wait for processing by the next page.

    Nehoo, the script (in the <head> tags): formApply being the name of the form, and so on.
    <script language="JAVASCRIPT">
    
    function validate() {
    
    if(formApply.firstName.value == "")
    {
    alert("Please complete all required fields.");
    return false;
    }
    
    if(formApply.surName.value == "")
    {
    alert("Please complete all required fields.");
    return false;
    }
    
    if(formApply.telephone.value == "")
    {
    alert("Please complete all required fields.");
    return false;
    }
    
    if(formApply.email.value == "")
    {
    alert("Please complete all required fields.");
    return false;
    }
    
    if(formApply.emailCheck.value == "")
    {
    alert("Please complete all required fields.");
    return false;
    }
    
    if(formApply.email.value != formApply.emailCheck.value)
    {
    alert("Emails do not match");
    return false;
    }
    
    if(formApply.uploadedfile.value == "")
    {
    alert("Please complete all required fields.");
    return false;
    }
    
    return true;
    }
    </script>
    

    So why wont it work with foxy ?


Comments

  • Registered Users Posts: 1,268 ✭✭✭hostyle


    So why wont it work with foxy ?

    Because its written using IE-specific code. Use the DOM!

    Something like this (untested and OTOH):
    if(document.forms['formApply'].elements['email'].value != document.forms['formApply'].elements['emailCheck'].value)
    {
    alert("Emails do not match");
    return false;
    }
    

    After testing it, the above works just fine, but heres a more complete version, just cause I was bored.
    <script type="text/javascript">
    <!-- 
    
    function validate() {
    	if (document.forms['formApply'].elements['email'].value != document.forms['formApply'].elements['emailCheck'].value) {
    		alert("Emails do not match");
    		return false;
    	}
    }
    
    function assignEvent() {
    	if (document.getElementById) {
    		var newloc = document.getElementById('formApply');
    		if (newloc) {
    			newloc.onsubmit = validate;
    		}
    	}
    }
    
    window.onload = function() {
    	assignEvent();
    }
    
    // -->
    </script>
    
    <form name="formApply" id="formApply" method="post" action="whatever.php">
    	<input type="text" name="email" value="" />
    	<input type="text" name="emailCheck" value="" />
    	<input type="submit" name="action" value="Do it!" />
    </form>
    


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    Lew

    I have some javascript checking form values for blank entries and so on, but it's not working with Firefox :/ I could use the processing PHP page to check the values that were just sent in, but I think its better to have the info displayed immediately on the entry page rather than having to wait for processing by the next page.

    Client-side validation is never a substitute for server-side validation; it's just a convenience. Do both.


Advertisement