check box clear select boxes

Y

yakuza

hi,

i want to know how to clear select boxes if i unselect a check box.

sample of form code

<input type="checkbox" name="truk" value="5">

<select name="day">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
</select>

<select name="month">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
</select>

<select name="year">
<option value=""></option>
<option value="2006">2006</option>
<option value="2007">2007</option>
</select>


best regards
 
R

Randy Webb

yakuza said the following on 6/11/2006 1:39 PM:
hi,

i want to know how to clear select boxes if i unselect a check box.

You set the selectedIndex of the select to 0.
 
E

Elegie

yakuza wrote:

Hi,
i want to know how to clear select boxes if i unselect a check box.
<input type="checkbox" name="truk" value="5">

Here, add the following attribute (the "this" keyword referring to the
checkbox object) :

onclick="foo(this)"

.... and then define your function.

<script type="text/javascript">
function foo(cbx){
var sel = ["day", "month", "year"], el=cbx.form.elements;
if(cbx.checked)
for(var ii=0; ii<sel.length; ii++)
el[sel[ii]].options[0].selected=true;
}
</script>


If you are to work with HTML forms, then I suggest you spend some time
and read the following article, which should give you a good insight
into manipulating forms.

<URL:http://www.jibbering.com/faq/faq_notes/form_access.html#faHead>

HTH
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top