populate the Dropdown list by client side using javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pskvenkat
    New Member
    • Mar 2008
    • 10

    populate the Dropdown list by client side using javascript

    Hi this is venkat,
    i have a drop downlist for country, i composed a code in javascript for that and its working in HTML page but i dont know how to call the same javascript function in asp.net(C#) dropdownlist. please advice me and send me code for how to call the function..
  • DontHave
    New Member
    • Jun 2007
    • 1

    #2
    Be specific in the question.

    You can call the javascript method on any event which you can do by writing it either in the aspx page or in the code with (control.attrib utes.add("[Event]","[javascript code or function call]"))

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by pskvenkat
      Hi this is venkat,
      i have a drop downlist for country, i composed a code in javascript for that and its working in HTML page but i dont know how to call the same javascript function in asp.net(C#) dropdownlist. please advice me and send me code for how to call the function..
      Hi Venkat :)

      JavaScript works in the browser (client side).
      Your C# code works on the web server (server side).
      You cannot call JavaScript functions from your C# code.

      What you can do is set each of your DropDownList Items to have an "onclick" event:

      [code=cpp]
      foreach(ListIte m i in MyCountryDropDo wnList.Items)
      { i.Attributes.Ad d("onclick","th eJavaScriptFunc tion();");}
      [/code]

      This will cause the JavaScript function to be called when ever the DropDownList item has be clicked on.

      If you need your C# code to generate your country list on the server, then you must implement this in C#. You cannot call your JavaScript function from the server.
      -Frinny

      Comment

      • pskvenkat
        New Member
        • Mar 2008
        • 10

        #4
        Hi Thanks for quick reply
        i need like below link- just click this url and see there is country option- http://www.24x7a2z.com/iff/ver2/feedback.html. after selecting the corresponding country, then i will store that selected country to DB? will it possible to do that? please let me know how it possible?...

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Originally posted by pskvenkat
          Hi Thanks for quick reply
          i need like below link- just click this url and see there is country option- http://www.24x7a2z.com/iff/ver2/feedback.html. after selecting the corresponding country, then i will store that selected country to DB? will it possible to do that? please let me know how it possible?...
          You could create a database with a table for your countries...the n you can populate your DropDownList with countries retrieved from the database.

          Normally when you have a form like that you are saving the person's information in some way. Saving it into a database is a good idea.

          -Frinny

          Comment

          Working...