change dropdownlist selected index with javascript

Discussion in 'ASP .Net' started by Antonio, Aug 9, 2005.

  1. Antonio

    Antonio Guest

    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?
    Antonio, Aug 9, 2005
    #1
    1. Advertising

  2. Antonio

    Lucas Tam Guest

    "Antonio" <> wrote in news:1123594526.368603.223910
    @z14g2000cwz.googlegroups.com:

    > 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


    --
    Lucas Tam ()
    Please delete "REMOVE" from the e-mail address when replying.
    http://members.ebay.com/aboutme/coolspot18/
    Lucas Tam, Aug 9, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Iain
    Replies:
    3
    Views:
    927
  2. Sobin Thomas
    Replies:
    1
    Views:
    903
    Munna
    Aug 12, 2008
  3. Nathan Sokalski
    Replies:
    0
    Views:
    604
    Nathan Sokalski
    Oct 5, 2008
  4. mldardy
    Replies:
    0
    Views:
    961
    mldardy
    Sep 28, 2010
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    277
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page