Need button to clear drop downs wo postback

J

Jeff User

Greeting

I built asp.net (V1.1) page.
I want to use this button to reset SelectedIndex=0 on several drop
down lists. However, I do not want to post back to server. The point
is to avoid the round trip.

It had an asp:button which would post back to the server when clicked
but changed it to an input button to avoid the postback. (If that is
not needed,let me know)

So, I now have
<input type=button value="clear" onclick="Clear_ddls()">

in header of page I have script
function Clear_ddls()
{
want to set ddlLastName.selectedIndex = 0;
}

I know the script runs because I put an alert message in there.
I do not know how to reference the drop down lists contained on my
asp.net page from in the script.
I tried different forms of document.get..., or Form1.ddlLastName,
etc.. but can not get it to work.

My form contains
<ASP:dropdownlist id="ddlLastName"
runat="server" bla bla></asp:dropdownlist>

This list (and others ) are populated on server side. That is ok for
me. I just want to be able to reset it on client side with script.

Can I do this?
thanks
Jeff
 
B

bruce barker \(sqlwork.com\)

you need to use the ClientId property of the controls to know the name. try:

function Clear_ddls()
{
document.getElementById('<%=ddlLastName.ClientId%>').selectedIndex =
0;
}


-- bruce (sqlwork.com)
 
J

Jeff User

Bruce

I have the script running wo any errors, but the drop down list does
not change appearance on the screen. Does this mean it isn't working
or do I have to do something to get the drop down to re-display itself
with its new index (assuming it has been reset to 0)

Thanks
Jeff
 
J

Jeff User

No other ideas?

Any body?

Jeff


you need to use the ClientId property of the controls to know the name. try:

function Clear_ddls()
{
document.getElementById('<%=ddlLastName.ClientId%>').selectedIndex =
0;
}


-- bruce (sqlwork.com)
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top