By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,051 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Select drop-down item to run an ASP.NET/javascript function?

P: 2
I hope someone can help me. When a user selects a new item from a
drop down list on an ASP.NET form, I'd like a javascript function to execute.
How can I do this?

I'm running the following configuration:
VS2005 - using VB.NET
ASP.NET 2.0
IIS 6.0
Windows XP, SP2

I have the following .aspx code behind my ASP.NET page. When a user presses button "btnClearTaskResults" the javascript function "ClearNodes()" DOES execute properly:

<asp:Button ID="btnClearTaskResults" runat="server" OnClientClick="javascript:clearNodes()" Text="Clear Task Results" />

<script language="javascript" type="text/javascript" src="javascript/WebMapApp.js"></script>
<script language="javascript" type="text/javascript">
function clearNodes() {$find('TaskResults1').clearAllNodes();}
</script>

However, I cannot figure out how to get similar functionality for a drop down list box. I tried adding a OnSelectedIndexChanged to my drop down .aspx code, as follows:

<asp:DropDownList ID="dropMapService" runat="server" OnSelectedIndexChanged="javascript:clearNodes()" AutoPostBack="true">

Unfortunately, I get the following 2 compile errors:
1. 'javascript' is not a member of 'ASP.mapterrain_aspx'.
2. Name 'clearNodes' is not declared

I'm new to javascript & I've mainly been programming in VB.NET, so I would greatly appreciate any help you could give me.

Thanks,

Julie
Sep 21 '08 #1
Share this Question
Share on Google+
2 Replies


P: 93
Hi,

You can call this event for the purpose of List Dropdown
Selectedindexchange ();
Sep 22 '08 #2

P: 2
Thanks for the info. I actually had a problem with the code that I was calling from my javascript function that caused the OnSelectedIndexChange event to not fire correctly.

I ended up doing a workaround by having a button right next to my drop down box, setting the postback = false for the drop down box & then having the user press the button after they change the drop down box so the button could call the javascript. Thanks for all of your help.

Julie
Sep 22 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.