Drop Down refresh keep selected value

Discussion in 'Javascript' started by Patrick, Sep 3, 2004.

  1. Patrick

    Patrick Guest

    Hello,

    I have a drop down list that when a value is selected the page
    refreshes itself but the selected value changes back to the default
    value. I would like to keep the selected value after the page is
    refreshed. any ideas?

    Thanks in advance.

    Patrick
     
    Patrick, Sep 3, 2004
    #1
    1. Advertising

  2. Patrick

    J. J. Cale Guest

    You haven't said how your document is being refreshed. If you are using the
    onchange handler in the select to call a function that repopulates the list
    it shouldn't be a problem. If you are submitting the form and the page is
    being refreshed you should do it server side. For the former
    ----------------------------------------------------
    // Before you repopulate the list trap the selection.
    function yourFunction() {
    var savedIndex = document.forms["your form
    name"].yourSelectList.selectedIndex;
    your code here.........
    // after you repopulate the list, programatically change the selection.
    document.forms["your form
    name"].yourSelectList.options[savedIndex].selected = true;
    }
    ----------------------------------------------------
    // alternatively you could pass it to the function that rewrites the select
    list.
    <select name = "yourSelectList" onchange =
    "yourFunction(this.selectedIndex)">
    function yourFunction( savedIndex )
    your code here.......
    document.forms["your form
    name"].yourSelectList.options[savedIndex].selected = true;
    }
    hope that helps

    "Patrick" <> wrote in message
    news:...
    > Hello,
    >
    > I have a drop down list that when a value is selected the page
    > refreshes itself but the selected value changes back to the default
    > value. I would like to keep the selected value after the page is
    > refreshed. any ideas?
    >
    > Thanks in advance.
    >
    > Patrick
     
    J. J. Cale, Sep 3, 2004
    #2
    1. Advertising

  3. Patrick

    Shawn Milo Guest

    What type of page is it? HTML, ASP, PHP, etc.?

    Shawn
     
    Shawn Milo, Sep 3, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page