Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Fetch value from dropdown into a text box using javascript

Fetch value from dropdown into a text box using javascript

Scheduled Pinned Locked Moved ASP.NET
csharpjavajavascriptasp-nettools
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amittinku
    wrote on last edited by
    #1

    1. Used ASP.NET controls: dropdown and textbox. 2. For the 1st time at page load, some default values should be populated in dropdown and 1st value in text box. Written the below code protected void Page_Load(object sender, EventArgs e)       {             if (!IsPostBack)             {                   DropDownList1.Items.Add("a");                   DropDownList1.Items.Add("b");                   DropDownList1.Items.Add("c");             TextBox1.Text = DropDownList1.SelectedValue;                         }       } 3. Set the autopostback of dropdown=False. So "DropDownList1_SelectedIndexChanged1" will not work. I have done this because after selecting any value in dropdown, post back should   not take place. 4. Now we have values in drop down. I want to select a value in dropdown and same selected value should be visible in text box. I want a java script for this. Not able to write it as not able to find any client event for dropdown. Actually there is event "onclientclick" for an asp.net button control, but did not find any such event for dropdown. So how to write java script code.

    S 1 Reply Last reply
    0
    • A amittinku

      1. Used ASP.NET controls: dropdown and textbox. 2. For the 1st time at page load, some default values should be populated in dropdown and 1st value in text box. Written the below code protected void Page_Load(object sender, EventArgs e)       {             if (!IsPostBack)             {                   DropDownList1.Items.Add("a");                   DropDownList1.Items.Add("b");                   DropDownList1.Items.Add("c");             TextBox1.Text = DropDownList1.SelectedValue;                         }       } 3. Set the autopostback of dropdown=False. So "DropDownList1_SelectedIndexChanged1" will not work. I have done this because after selecting any value in dropdown, post back should   not take place. 4. Now we have values in drop down. I want to select a value in dropdown and same selected value should be visible in text box. I want a java script for this. Not able to write it as not able to find any client event for dropdown. Actually there is event "onclientclick" for an asp.net button control, but did not find any such event for dropdown. So how to write java script code.

      S Offline
      S Offline
      sris 426
      wrote on last edited by
      #2

      BY using ajax, you can get the result.Why dont you try ajax

      C 1 Reply Last reply
      0
      • S sris 426

        BY using ajax, you can get the result.Why dont you try ajax

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Perhaps he cares about writing efficient code that is scalable ?

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups