Javascript required input validation issue

Discussion in 'JavaScript' started by l3l00, Mar 15, 2013.

  1. #1
    
    <script> 
    function checkforblank() { 
         
        var errormessage = ""; 
         
        if (document.getElementById('emailemail').value == "") { 
            errormessage += "Enter your email \n"; 
            document.getElementById('emailemail').style.borderColor= "red"; 
              
            } 
                if (document.getElementById('name1name1').value == "") { 
            errormessage += "Enter your first name \n"; 
            document.getElementById('name1name1').style.borderColor= "red"; 
              
            } 
                        if (document.getElementById('name2').value == "") { 
            errormessage += "Enter your last name \n"; 
            document.getElementById('name2').style.borderColor= "red"; 
              
            } 
                                if (document.getElementById('address').value == "") { 
            errormessage += "Enter your address \n"; 
            document.getElementById('address').style.borderColor= "red"; 
              
            } 
                                if (document.getElementById('city').value == "") { 
            errormessage += "Enter your city \n"; 
            document.getElementById('city').style.borderColor= "red"; 
              
            } 
                                if (document.getElementById('state').value == "") { 
            errormessage += "Enter your state \n"; 
            document.getElementById('state').style.borderColor= "red"; 
              
            } 
                                if (document.getElementById('zip').value == "") { 
            errormessage += "Enter your zip \n"; 
            document.getElementById('zip').style.borderColor= "red"; 
              
            } 
                                if (document.getElementById('phone').value == "") { 
            errormessage += "Enter your phone \n"; 
            document.getElementById('phone').style.borderColor= "red"; 
              
            } 
            if (errormessage != "") { <!-- if it is not empty --> 
            alert(errormessage); 
            return false; <!-- Makes Script not submit, or paused --> 
              
            } 
         
        } 
    </script>
    
    Code (markup):
    onsubmit="checkforblank()"
    Code (markup):
    it does seem to work just fine, it pulls the pop up message but when you hit okay. it takes them to the next page no matter what?
     
    l3l00, Mar 15, 2013 IP
  2. l3l00

    l3l00 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    fixed issue, but if someone were to enter in the fields and press submit
    it does nothing. they would have to refresh the page...?
     
    l3l00, Mar 15, 2013 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    The code you show has nothing to do with the next page. Where does the form direct to?
     
    Rukbat, Mar 17, 2013 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #4
    Yeah, this is kind of another case of "if we can't see the HTML the script is doing stuff to, we can't tell you what's wrong"

    CSS without the HTML it's working on is gibberish... Javascript without the HTML it's working on is gibberish, etc, etc...
     
    deathshadow, Mar 18, 2013 IP