change dropdownlist selected index with javascript

A

Antonio

Hi, in my page's <body tag>'s "onload" javascript event I want to call
a javascript method that will change the selected index of a drop down
list. I want it to happen every time the page gets refreshed but not
do it with codebehind, it has to be javascript.

How do I do it?
 
L

Lucas Tam

Hi, in my page's <body tag>'s "onload" javascript event I want to call
a javascript method that will change the selected index of a drop down
list. I want it to happen every time the page gets refreshed but not
do it with codebehind, it has to be javascript.

How do I do it?



document.getElementById('dropdownlistname').selectedIndex = indexNumber

You can get the dropdownlist name via the .NET ClientID property of each
control.

So you'll have to dynamically output the javascript via codebehind. Take
a look at the function Page.RegisterClientScriptBlock on an example of
including dynamically written javascript.

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/cpref/html/frlrfSystemWebUIPageClassRegisterClientScriptBlockTopic.as
p
 

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,810
Latest member
Kassie0918

Latest Threads

Top