javascript - Check dropdown before submit -
Before using this I will use this code to select the dropdown opton. On my page I have 3 dropdown menus, but only the first job is right.
Is there a way to extend the function to the second and third dropdowns?
My script: My HTML: should be unique and is used only once I recommend you to give them all the class In addition, instead, select a category for the same reason, both: Your jQuery will also be changed in:
& lt; Script type = "text / javascript" & gt; Click (function () {var year = $ ('# option option: selected'). Val (); if (year == "") {$ ("# Msg"). Html ("Please select one year Do "); return back;}}}};}); & Lt; / Script & gt;
& lt; Div id = "msg" & gt; & Lt; / Div & gt; & Lt; Form method = "post" verb = "" & gt; & Lt; Select id = "year" & gt; & Lt; Option value = "" & gt; OLLA & lt; / Options & gt; & Lt; Options & gt; 1991 & lt; / Options & gt; & Lt; Options & gt; 1992 & lt; / Options & gt; & Lt; Options & gt; 1993 & lt; / Options & gt; & Lt; Options & gt; 1994 & lt; / Options & gt; & Lt; Options & gt; 1995 & lt; / Options & gt; & Lt; / Select & gt; & Lt; Div id = "msg" & gt; & Lt; / Div & gt; & Lt; Form method = "post" verb = "" & gt; & Lt; Select id = "year" & gt; & Lt; Option value = "" & gt; OLLA & lt; / Options & gt; & Lt; Options & gt; 1991 & lt; / Options & gt; & Lt; Options & gt; 1992 & lt; / Options & gt; & Lt; Options & gt; 1993 & lt; / Options & gt; & Lt; Options & gt; 1994 & lt; / Options & gt; & Lt; Options & gt; 1995 & lt; / Options & gt; & Lt; / Select & gt; & Lt; Input type = "submit" name = "submit" id = "submit" & gt; & Lt; / Form & gt;
msg , e.g.
& lt; Div class = "msg" & gt; & Lt; / Div & gt; ... & lt; Div class = "msg" & gt; & Lt; / Div & gt;
& lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {$ ("submit") (function () {var year = $ ('. Year option: selected'). Val (); if (year == "" ) {$ (".mssg") .html ("Please select one year"); return back;}}});}); & Lt; / Script & gt;
Comments
Post a Comment