javascript - Hide DIV when make selection -
I have 2 choices if a user submits form without selecting the dropdown, a message is displayed on DIV.
SCRIPT:
$ (document) .ready (function () {$ ("#") Click (function () {if (document.getElementById ('sel 'SelectedIndex == 0) $ ("# msg") .html ("Please select 1"); if (document.getElementById (' Sel2 '). SelectedIndex == 0) $ ("# msg2") .html ("Please select 2");});}); Form:
& lt; Form id = "form1" & gt; & Lt; Div id = "msg" & gt; & Lt; / Div & gt; & Lt; Select id = "sel" & gt; & Lt; Option value = "" & gt; - Select - & lt; / Options & gt; & Lt; Option value = "Warr 1" & gt; Restored 1 & lt; / Options & gt; & Lt; Option value = "Warr2" & gt; Restore 2 & lt; / Options & gt; & Lt; / Select & gt; & Lt; Div id = "msg2" & gt; & Lt; / Div & gt; & Lt; Select id = "sel2" & gt; & Lt; Option value = "" & gt; - Select - & lt; / Options & gt; & Lt; Option value = "Warr 1" & gt; Restored 1 & lt; / Options & gt; & Lt; Option value = "Warr2" & gt; Restore 2 & lt; / Options & gt; & Lt; / Select & gt; & Lt; Input type = "button" id = "go" value = "go" /> & Lt; / Form & gt; Click the
$ ("# go") (function () { ($ ('$ Sel'). Val () == '') $ ("# msg"). Text ("Please select 1"); if ($ ('# sel2'). Val () == '') $ ("# Msg2"). Text ("Please select 2");); $ ('# Sel') Change (function () {$ ('# msg'). Hide ()}) $ ('# sel2'). Change (function () {$ ('# msg2'). ()}) and jsfiddle is working:
Comments
Post a Comment