Forum Moderators: open

Message Too Old, No Replies

How to tell which drop down list is being changed

         

dreaming of nascar

12:09 am on Apr 29, 2005 (gmt 0)

10+ Year Member



I have a form on a webpage that I want to be able to allow the user to select from one of the two drop down lists in a form. When the user selects an option I have an onChange=javascript:this.form.submit(); on one of the drop downs right now and it works perfectly. My problem is that when I add it to the other list, I do not know how to tell which list the information was sent from being that both values in the drop down lists will be send in the query string. Can anyone help me determine which list was selected? Thanks!

DON

orion_rus

6:07 am on Apr 29, 2005 (gmt 0)

10+ Year Member



I think the best way not ot use form,
if you have a select u can make action it like this:
<select name='my' onChange='index.php?my='+this.value>
<option>Choose Country</option>
<option value='1'>Russia</option>
<option value='2'>Usa</option>
</select>
and on change u go to page like this: index.php?my=1
Another idea is to create a hidden input field
like : <input type='hidden' name='selectedfield' id='selectedfield' />
and before this form submit u should make
javascript:document.getElementById('selectedfield').value='input1';this.form.submit()
by this you can find out what <select> was hitted...
Good luck to you!

rocknbil

3:18 pm on Apr 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or move the actual submit into a function:

<form>
<select name="lista" onChange="chkLists(this.form,this.name);">
<option value="a">a</a>
<option value="b">b</a>
</select>
<select name="listb" onChange="chkLists(this.form,this.name);">
<option value="a">a</a>
<option value="b">b</a>
</select>
<input type="hidden" name="whichlist" value="">
</form>

function chkLists(form,which) {
form.whichlist.value=which;
form.submit();
}

OR . . . a server-side solution is even more simple. If you're submitting onChange, simply make the first element of your select lists blank,

<select name="lista" onChange="this.form.submit();">
<option value="">Please Select</a>
<option value="a">a</a>
<option value="b">b</a>
</select>

Then in the programming language of your choice,

$selectedList = ($qs{'a'} ne '')?$qs{'a'}:$qs{'b'};

But if they've somehow managed to submit them both blank, return back to the page to select:

if (! $selectedList) { &html("Same Page with Message"); }