Drop Down refresh keep selected value

P

Patrick

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. J. Cale

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
 

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,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top