dropdown box change index to matching

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • .nLL

    dropdown box change index to matching

    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="docum ent.getElementB yId('myday').se lectedIndex=0">
    <option value="20080401 " selected="selec ted" >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="selec ted">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,200804 02,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).len gth) // Invalid bound, return
    return str; // entire string
    else // Valid bound, return appropriate substring
    return String(str).sub string(0,n);
    }
    --------------------------------------------------------------------------------------------------

    so, how can i do it?
    select name="myday"
    onChange="docum ent.getElementB yId('mymonth'). selectedIndex=? ??????????????? ??????????????? ??">

    can anyone give me a clue?

    thanks


  • Bart Van der Donck

    #2
    Re: dropdown box change index to matching

    .nLL wrote:
    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="docum ent.getElementB yId('myday').se lectedIndex=0">
    'myday' is a name-attribute, not an ID.
    <option value="20080401 " selected="selec ted" >April-2008 (26158)</option>
    Must be:
    <option value="20080401 " 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="selec ted">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,200804 02,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:


    Hope this helps,

    --
    Bart

    Comment

    Working...