SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Wizard rbutler's Avatar
    Join Date
    Jul 2003
    Location
    Springfield, MO
    Posts
    1,867
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JS validation - onsubmit

    Here's my inquiry: I have programmed this simple js validation for my form:

    Code:
    <script type="text/javascript">
    function userinformation(){
    var message="Please complete the following: \n\n";
    var noerrors=message;
    
    var dayselected=document.topform.day.selectedIndex;
    if(document.topform.day.options[dayselected].value=="null"){
    message+="Please select a day\n";
    }
    
    if(document.topform.daterequested.value==""){
    message+="Please provide a requested tour date\n";
    }
    
    var numberattendinglist=document.topform.numberattending.selectedIndex;
    if(document.topform.numberattending.options[numberattendinglist].value=="null"){
    message+="Please select a day\n";
    }
    
    if(document.topform.firstname.value==""){
    message+="Please provide your first name\n";
    }
    
    if(document.topform.lastname.value==""){
    message+="Please provide your last name\n";
    }
    
    if(document.topform.address.value==""){
    message+="Please provide your address\n";
    }
    
    if(document.topform.city.value==""){
    message+="Please provide your city\n";
    }
    
    if(document.topform.state.value==""){
    message+="Please provide your state\n";
    }
    
    if(document.topform.zip.value==""){
    message+="Please provide your zip code\n";
    }
    
    if(document.topform.highschool.value==""){
    message+="Please provide your high school\n";
    }
    
    if(document.topform.gradyear.value==""){
    message+="Please provide your graduation year\n";
    }
    
    if(document.topform.phonenumber.value==""){
    message+="Please provide your phone number\n";
    }
    
    
    if(message==noerrors){
            topform.submit();    
        }else{
            alert(message);
        return false;
        }
    }
    On my form tag, I have:

    Code:
    <form onsubmit="userinformation();return false">
    However, my form will not submit, which with the return false statement on the onsubmit handler, it won't. However, in my validation check at the end of the function, I have used the submit method relating to my form to execute the form and it doesn't work. Is there something simple I'm missing?
    Ryan Butler

    Midwest Web Design

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of "topform.submit();" just try "return true;"

  3. #3
    SitePoint Wizard rbutler's Avatar
    Join Date
    Jul 2003
    Location
    Springfield, MO
    Posts
    1,867
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I tried that. Didn't work. Why does my solution work in FF, but not IE?
    Ryan Butler

    Midwest Web Design

  4. #4
    SitePoint Wizard rbutler's Avatar
    Join Date
    Jul 2003
    Location
    Springfield, MO
    Posts
    1,867
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Found my solution:

    Code:
     
    <form onsubmit="return userinformation(this.form)">
    Ryan Butler

    Midwest Web Design

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Weird, as your function doesn't even accept parameters...

  6. #6
    SitePoint Wizard rbutler's Avatar
    Join Date
    Jul 2003
    Location
    Springfield, MO
    Posts
    1,867
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Even weirder, one form field is screwing everything up and it's the form field you helped me on yesterday. Really freaking odd!
    Ryan Butler

    Midwest Web Design


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •