Friday, 15 February 2013

javascript - Validation of Dropdown list doesn't work -


The following is the code to validate the form with the radio buttons, text boxes and dropdown lists. Javascript for validating radio buttons and text boxes but javascript does not work for dropdown Can you please tell me what I have done?

Please help!

Thanks in advance.

  & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Script type = "text / javascript" & gt; Validate function (form) {var check = zero; Var name1 = document.forms ["information"] ["first name"]. value; Var n = name1.split (""); Var name = n [0]; Var sex = document.forms ["notice"] ["gender"]; Var e = document.getElementById ("prof1"); Var strUser = e.options [e.selectedIndex] .value; Var strUser1 = e.options [e.selectedIndex] .text; If (name == faucet = name == "") {warnings ('enter first name'); return false; } (Var i = 0; i & lt; 2; i ++) {if (gender [i].) {Checked = sex [i]; Back true; }} If (check == tap) {warning ('enter sex'); return false; } If (strosor == 0) {warning ("enter business"); return false; }} & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form name = "info" onsubmit = "return validateForm ()" method = "post" & gt; & Lt; Text style = "color: red" & gt; * & Lt; / Text & gt; First name: & lt; Input type = "text" name = "first name" & gt; & Lt; Br> & Lt; Br> Last name: & lt; Input type = "text" name = "last name" & gt; & Lt; Br> & Lt; Br> & Lt; Text style = "color: red" & gt; * & Lt; / Text & gt; Gender: & lt; Input type = "radio" name = "gender" value = "male" & gt; Men & lt; Input type = "radio" name = "gender" value = "woman" & gt; Women & lt; Br> & Lt; Br> & Lt; Text style = "color: red" & gt; * & Lt; / Text & gt; Profession: & lt; Select id = "prof1" & gt; & Lt; Option value = "0" & ​​gt; & Lt; / Options & gt; Select & lt; Option value = "1" & gt; Engineer & lt; / Options & gt; & Lt; Option value = "2" & gt; Doctor & lt; / Options & gt; & Lt; Option value = "3" & gt; Lawyer & lt; / Options & gt; & Lt; Option value = "4" & gt; Other & lt; / Options & gt; & Lt; / Select & gt; & Lt; Input type = "submit" value = "submit" /> & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;    

  if (gender [i] is checked) {checked = Sex [i]; Back true; } Remove the returns above the correct    

No comments:

Post a Comment