clearing list

B

Brian

Hi

I'm working on a site that has a form on it to do an advanced search on
a database, in the form are 2 list (<select>)

Both these list have items in them, what I want to do is if an items it
selected from list A then it sets list B value to null and of cause the
other way round. The reason is I need to make sure that when the
form is submitted I only pass an item from either list A or B not both
is I do a test on each variable to see what has been selected

I have tried onChange="this.form.town.value=''"

any ideas?

Brian
 
R

RobG

Brian said:
Hi

I'm working on a site that has a form on it to do an advanced search on
a database, in the form are 2 list (<select>)

Both these list have items in them, what I want to do is if an items it
selected from list A then it sets list B value to null and of cause the
other way round. The reason is I need to make sure that when the
form is submitted I only pass an item from either list A or B not both
is I do a test on each variable to see what has been selected

I have tried onChange="this.form.town.value=''"

any ideas?

Use an onchange function on each list that sets the other to a default
empty option (or has some value you know to ignore).

<form action="">
<select name="listA" onchange="this.form.listB.selectedIndex=0;">
<option selected></option>
<option value="A1">A1</option>
<option value="A2">A2</option>
</select>
<select name="listB" onchange="this.form.listA.selectedIndex=0;">
<option selected></option>
<option value="B1">B1</option>
<option value="B2">B2</option>
</select>
</form>
 
T

Thomas 'PointedEars' Lahn

Brian said:
[...] The reason is I need to make sure that when the form is submitted I
only pass an item from either list A or B not both is I do a test on each
variable to see what has been selected

Note that it does not work without client-side script support:
I have tried onChange="this.form.town.value=''"

If `town' is the name of a select control, this is not supposed to work.
The `value' attribute/property of those objects only specifies the selected
value. Use this instead:

var o = selectElement.options;
if ((o.length = 0) > 0)
{
while (o.length > 0)
{
o[0] = null;
}
}


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top