dropdown box change index to matching

N

.nLL

Hi, i ma trying to change a dropdown box index to mathing value of on
another dropdown box in same form. here is the form

--------------------------------------------------------------------------------------------------------------------------
<form method="post" name="myform" action="default.asp">
<p>
Select Month:
<select name="mymonth"
onChange="document.getElementById('myday').selectedIndex=0">
<option value="20080401" selected="selected" >April-2008 (26158)</option>
<option value="20080301" >March-2008 (2)</option>
<option value="20080201" >February-2008 (1)</option>
</select>

Day:
<select name="myday" >
<option value="0" >All days</option>
<option value="20080401" >1-Tuesday (1)</option>
<option value="20080420" >20-Sunday (2)</option>
<option value="20080421" >21-Monday (1)</option>
<option value="20080425" selected="selected">25-Friday (26154)</option>
</select>
<input type="submit" value="View"/>
</p>
</form>
-------------------------------------------------------------------------------------------------------------------------------------------
when mymonth changes scipt sets myday seleceted index to 0 (ALL days)
and hits submits, data from that month comes but user can first select month
then change day on myday selectbox and hit submit. that would bring wrong
data. so i am trying to prevent that
by changing mymonth data to matching value of myday onchange vent on myday

mymnth value always unique and myday data always incremental (as in
20080401,20080402,20080403)
you would notice myday value has 2 more characters than mymonth data but to
sort this problem out i've got below function

-------------------------------------------------------
function Left(str, n)
{
if (n <= 0) // Invalid bound, return blank string
return "";
else if (n > String(str).length) // Invalid bound, return
return str; // entire string
else // Valid bound, return appropriate substring
return String(str).substring(0,n);
}
--------------------------------------------------------------------------------------------------

so, how can i do it?
select name="myday"
onChange="document.getElementById('mymonth').selectedIndex=?????????????????????????????????">

can anyone give me a clue?

thanks
 
B

Bart Van der Donck

.nLL said:
Hi, i ma trying to change a dropdown box index to mathing value of on
another dropdown box in same form. here is the form

--------------------------------------------------------------------
<form method="post" name="myform" action="default.asp">
<p>
Select Month:
<select name="mymonth"
onChange="document.getElementById('myday').selectedIndex=0">

'myday' is a name-attribute, not an ID.
<option value="20080401" selected="selected" >April-2008 (26158)</option>

Must be:
<option value="20080301"  >March-2008 (2)</option>
<option value="20080201"  >February-2008 (1)</option>
</select>

Day:
<select name="myday" >
<option value="0" >All days</option>
<option value="20080401" >1-Tuesday (1)</option>
<option value="20080420" >20-Sunday (2)</option>
<option value="20080421" >21-Monday (1)</option>
<option value="20080425" selected="selected">25-Friday (26154)</option>
</select>
<input type="submit" value="View"/>
</p>
</form>
--------------------------------------------------------------------
when mymonth changes scipt sets myday seleceted index to  0 (ALL days)
and hits submits, data from that month comes but user can first select month
then change day on myday selectbox and hit submit. that would bring wrong
data. so i am trying to prevent that
by changing mymonth data to matching value of myday onchange vent on myday

mymnth value always unique and myday data always incremental (as in
20080401,20080402,20080403)
[...]

I think you actually don't need any javascript. The selected date is
all the server asks; it could easily strip the month from that if need
be.

<select name="myday">
<option value="20080428">Monday, April 28 2008</option>
<option value="20080509">Friday, May 9 2008</option>
<option value="20080524">Saturday, May 24 2008</option>
<option value="20080608">Sunday, June 8 2008</option>
</select>
<input type="submit">

...does exactly the same and is much more efficient design.

If you want two boxes anyhow, here is a fine example:
http://www.javascripttoolbox.com/lib/dynamicoptionlist/

Hope this helps,
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top