drop down menu - Why is this javascript not working on my site? -


I am trying to cascade the filter according to the country, in which States should filter, with many codes I My site was trying to work, one of the codes I use works well when I use it as a separate demo test code and give the results according to my requirement, But when I in my project So using C code it does not work.

My script code is below:

  & lt; script type = "text / javascript" & gt; Var Country = New Array ('United States', 'Indonesia', 'Thailand', 'Australia', 'Germany', 'Japan'); Var state = new array (); State ["United States"] = New Array ("Q", "We", "Er", "RT"); State ["Indonesia"] = New Array ("as", "SD", "DF"); Function Resetform (The Form) {/ * Reset Country * / theform.country.options [0] = New Option ("Please Select Country", ""); For (var i = 0; i & lt; country.length; i ++) {theform.country.options [i + 1] = new option (country [i], country [i]); } Theform.country.options [0]. Selected = true; / * Reset state * / theform.state.options [0] = new option ("Please select a state", ""); Theform.state.options [0]. Selected = true; } Updatetestate (the form) {var make = theform.country.options [theform.country.options.selectedIndex] .value; Var newstate = state [make]; Theform.state.options.length = 0; theform.state.options [0] = new option ("Please select a state", ""); (Var i = 0; i & lt; newstate.length; i ++) {theform.state.options [i + 1] = new option (newest [i], newest [i]); } Theform.state.options [0]. Selected = true; } & Lt; / Script & gt;   

And my HTML code is also below:

  & lt; Form method = "get" name = "autoselectform" & gt; & Lt; Div class = "control-group" & gt; & Lt; Label & gt; COUNTRY & lt; span style = "font-size: 13px; font-weight: normal; display: none;" & Gt; (Max2) & lt; / Span & gt; & Lt; / Label & gt; & Lt; Select name = "country" size = "2" style = "width: 100%; height: 25px;" Class = "selectinput" id = "filCountry" onchange = "updatestate (this.form)" & gt; & Lt; / Select & gt; & Lt; / Div & gt; & Lt; Div class = "control-group" & gt; & Lt; Label & gt; State & lt; Span style = "font-size: 13px; font-weight: normal; display: none;" & Gt; (Max2) & lt; / Span & gt; & Lt; / Label & gt; & Lt; Choose name = "state" style = "width: 100%; height: 25px;" Class = "selected input" id = "filState" & gt; & Lt; / Select & gt; & Lt; / Div & gt; & Lt; Form & gt;    

You have additional locations for the United States in your array . First you have to fix that one

  // var country = new array ('United States', 'Indonesia', 'Thailand', 'Australia', 'Germany', 'Japan' ); Var Country = New Array ('United States', 'Indonesia', 'Thailand', 'Australia', 'Germany', 'Japan');   

And what you need to do before populating the state option in the code, you will have to check that states are defined in state The array for the selected country and whether you want them to enter the state ["United States"] and state ["Indonesia"] , You can use the .hasOwnProperty () method to check whether the selected countries are present or not State in the form of a key in the array.

  return (! State.hasOwnProperty (make)) return;   



Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -