View Full Version : select drop down ADDING a parameter to the GET url

Mar 21st, 2009, 09:54 AM
I have a language drop down menu at the top of every page. The idea is you click the drop down, select your new language and the page reloads in that language. Works perfect. The only problem is if the page has OTHER parameters in its existing url. For example, if I'm at www.example.com/person?name=Scott and I try to change the language to en_US, I want the page www.example.com/person?name=Scott&language=en_US to be loaded. However, what actually happens is www.example.com/person?language=en_US is loaded :(. Here's my code:

<form action="/person?name=Scott" method="get">
<select name="language" onchange="this.form.submit();">
<option value="en_US" selected="selected">English (United States)</option>
<option value="ro_RO">Romanian (Romania)</option>

So my question is, is there an easy way to do what I want? Or do I have to insert <input type="hidden"> elements for each existing parameter in the url on each page?

Mar 21st, 2009, 03:39 PM
Thats annoying. Is there a reason you don't want to put the hidden elements in. Are you using php because if so you could write a script to generate the hidden elements something like

foreach($_GET as $key => $value)
echo '<input type="hidden" name="'.$key.'" value="'.$value.'">';

Mar 22nd, 2009, 12:25 AM
Thanks timgolding, I was just hoping there was a simple flag I needed to set to enable what I wanted. I'm using Java/Spring, I'll just create those hidden elements.