forms - Javascript select() value -


I'm sure it's super easy, but for some reason I can not understand it once.

I need to create a form on the page with the following fields and rules. If the user submits a form, but the rule of any area is broken, then the user is listed to advise Be treated. I do not have permission to use jQuery Field 01 & amp; Field02 is a box. Field 03 & amp; Field04 is a box.

  • Field 01: "Username" - Rule 01: can not be blank, Behavior 101: Focus on it by using Focus. Field 02: "username" - Rule02: can not be blank, behavior 02: warn the user that "username is required"
  • field 03: "birthday" - rule 360: Must be numeric, Behavior 03: Select the value using Select ().
  • Field 04: "Birthday" - Must be Between Rule 4: 1900 - 2012, Behaviour04: Birthday Text Box Background Color Yellow.

    It's still up to me ... conflict with field 03;

    HTML:

      & lt ;! DOCTYPE html & gt; Field 04.  

    & lt; Html & gt; & Lt; Top & gt; & Lt; Script defer = "defer" type = "text / javascript" src = "dawid_spamer_Assign01.js" & gt; & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Div id = "div1" & gt; & Lt; Form name = "myForm" action = "demo_form.php" onsubmit = "return validateForm ()" method = "post" & gt; Username: & lt; Input type = "text" id = "user name" name = "user name" & gt; & Lt; Br> Birth year: & lt; Input type = "select" id = "birth year" name = "birth year" & gt; & Lt; Br> & Lt; Br> & Lt; Input type = "submit" value = "submit" & gt; & Lt; / Form & gt; & Lt; / Div & gt; & Lt; Div id = "div2" & gt; & Lt; Img src = "cat.jpg" id = "im1" name = "picture 1" /> & Lt; Img src = "dog.jpg" id = "im2" name = "image2" /> & Lt; Img src = "fish.jpg" id = "im3" name = "image3" class = 'double' / & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;

    JS:

      document.getElementById ("user name") in separate file. Focus (); // Validate the focus on the text box function (form) {var x = document.forms ["myForm"] ["user name"]. Values; If (x == "") {Warning ("username is required!"); // Note the text box document.getElementById ("username"). Focus (); return false; // verification has failed} other {back true; // Verification Success}}    

    Try

     . Document.getElementById ("user name") focus (); // Validate the focus on the text box function (form) {var x = document.forms ["myForm"] ["user name"]. Values; If (x == "") {Warning ("username is required!"); // Note the text box document.getElementById ("username"). Focus (); return false; // verification failed} var dob = document.forms ["myForm"] ["birth year"]; Var y = dob.value; If (! (/ ^ \ D + $ /. Test (y))) {Warning ('must be number'); Dob.select (); return false; } Back true; }   

    Demo:

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -