Need button to clear drop downs wo postback

  • Thread starter Thread starter Jeff User
  • Start date Start date
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
 
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)
 
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
 
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)
 
Back
Top