Friday, 15 April 2011

javascript - Make URL start select dropdown -


I have two select boxes (dropdown) and I have to create a URL to start this dropdown. Example:

  & lt; Form name = "states_cities" & gt; & Lt; Select name = "state" & gt; & Lt; Option value = "AC" & gt; Acre & lt; / Options & gt; & Lt; Option value = "rj" & gt; Rio de Janeiro & lt; / Options & gt; & Lt; Option value = "sp" & gt; Sao Paulo & lt; / Options & gt; & Lt; Option value = "to" & gt; Tolkentis & lt; / Options & gt; & Lt; / Select & gt; & Lt ;! - Cities of "Rio de Janeiro" - & gt; & Lt; Choose Name = "Cities" & gt; & Lt; Option value = "Quimedas" & gt; Qumadáos & lt; / Option & gt; & Lt; Option value = "Volta-redodo" gt; Volta Redando & lt; / Options & gt; & Lt; Option value = "nova-iguacu" & gt; Nova Iguaçu & lt; / Options & gt; & Lt; / Select & gt; & Lt; Button type = "submit" value = "go" & gt; & Lt; / Form & gt;  

and I need to create a URL instance:

or

when the user clicks!

What better way to do this?

You should use jQuery in this way to get the selected option:

 
  & lt; Script src = "https://ajax.googleapis.com/ajax/libs/jquery/ 1.11.1 / jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Select name = "states" id = "state" & gt; & Lt; Option value = "AC" & gt; Acre & lt; / Options & gt; & Lt; Option value = "rj" & gt; Rio de Janeiro & lt; / Options & gt; & Lt; Option value = "sp" & gt; Sao Paulo & lt; / Options & gt; & Lt; Option value = "to" & gt; Tolkentis & lt; / Options & gt; & Lt; / Select & gt; & Lt ;! - Cities of "Rio de Janeiro" - & gt; & Lt; Choose Name = "Cities" ID = "Cities" & gt; & Lt; Option value = "Quimedas" & gt; Qumadáos & lt; / Option & gt; & Lt; Option value = "Volta-redodo" gt; Volta Redando & lt; / Options & gt; & Lt; Option value = "nova-iguacu" & gt; Nova Iguaçu & lt; / Options & gt; & Lt; / Select & gt; & Lt; Button type = "submit" id = "go" & gt; Go & lt; / Button & gt;  


No comments:

Post a Comment