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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • juliek
    New Member
    • Sep 2008
    • 2

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

    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 "btnClearTaskRe sults" the javascript function "ClearNodes ()" DOES execute properly:

    <asp:Button ID="btnClearTas kResults" runat="server" OnClientClick=" javascript:clea rNodes()" Text="Clear Task Results" />

    <script language="javas cript" type="text/javascript" src="javascript/WebMapApp.js"></script>
    <script language="javas cript" type="text/javascript">
    function clearNodes() {$find('TaskRes ults1').clearAl lNodes();}
    </script>

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

    <asp:DropDownLi st ID="dropMapServ ice" runat="server" OnSelectedIndex Changed="javasc ript:clearNodes ()" AutoPostBack="t rue">

    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
  • Rsmastermind
    New Member
    • Sep 2008
    • 93

    #2
    Hi,

    You can call this event for the purpose of List Dropdown
    Selectedindexch ange ();

    Comment

    • juliek
      New Member
      • Sep 2008
      • 2

      #3
      Thanks for the info. I actually had a problem with the code that I was calling from my javascript function that caused the OnSelectedIndex Change 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

      Comment

      Working...