Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Firefox form checking

  • 22-06-2005 03: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, Registered Users 2 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, Registered Users 2 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