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:

  & 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;   

My HTML:

  & 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;    

should be unique and is used only once I recommend you to give them all the class msg , e.g.

  & lt; Div class = "msg" & gt; & Lt; / Div & gt; ... & lt; Div class = "msg" & gt; & Lt; / Div & gt;   

In addition, instead, select a category for the same reason, both:

    

Your jQuery will also be changed in:

  & 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

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 -