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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. How can I set TextBox value from asp.net Listbox, because I popuplate asp.net Listbox through java script..

How can I set TextBox value from asp.net Listbox, because I popuplate asp.net Listbox through java script..

Scheduled Pinned Locked Moved Web Development
csharpjavaasp-nettoolsquestion
3 Posts 2 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.
  • V Offline
    V Offline
    Vishnu Narayan Mishra
    wrote on last edited by
    #1

    How can I set TextBox value from asp.net Listbox, because I popuplate asp.net Listbox through java script.. I tried it by calling the java script function onChange(and onSelectedIndexChange) event of list box, but event is not calling java script function from here.. following is my code--

    onChange="setTextBoxValue(this.value);">

    function setTextBoxValue(e) { //var strListBoxName = document.getElementById('lstShowHistory'); document.getElementById('txtUrlLink').value = e ; //strListBoxName.options[strListBoxName.selectedIndex].text ; //;options[document.getElementById('lstShowHistory').selectedIndex].text; } the list box is popuplate on mouse over event on the text box... txtUrlLink.Attributes.Add("onfocus", "ShowList();"); function ShowList() { getCookie(); document.getElementById('helptypediv').style.visibility='visible';return false; } function getCookie() { if(document.cookie) { var strListBox = document.getElementById('lstShowHistory'); var ls1= document.cookie.split("="); if (ls1.length >1) { var ls2 = ls1[1].split("|"); var count = ls2.length; var strLink = ""; var optionItem; //Clear the previous options from the list for(var lstCount = strListBox.options.length-1; lstCount>-1; lstCount--) { strListBox.options[lstCount] = null; } if(count >= 2 ) { for(var x = count-1; x>=0; x--) { var ls3=ls2[x];//[x].split("|"); strLink+= ls3; optionItem = new Option(ls3, ls3, false, false); strListBox.options[strListBox.length] = optionItem; } } } } }

    Vishnu Narayan Mishra Software Engineer

    C 1 Reply Last reply
    0
    • V Vishnu Narayan Mishra

      How can I set TextBox value from asp.net Listbox, because I popuplate asp.net Listbox through java script.. I tried it by calling the java script function onChange(and onSelectedIndexChange) event of list box, but event is not calling java script function from here.. following is my code--

      onChange="setTextBoxValue(this.value);">

      function setTextBoxValue(e) { //var strListBoxName = document.getElementById('lstShowHistory'); document.getElementById('txtUrlLink').value = e ; //strListBoxName.options[strListBoxName.selectedIndex].text ; //;options[document.getElementById('lstShowHistory').selectedIndex].text; } the list box is popuplate on mouse over event on the text box... txtUrlLink.Attributes.Add("onfocus", "ShowList();"); function ShowList() { getCookie(); document.getElementById('helptypediv').style.visibility='visible';return false; } function getCookie() { if(document.cookie) { var strListBox = document.getElementById('lstShowHistory'); var ls1= document.cookie.split("="); if (ls1.length >1) { var ls2 = ls1[1].split("|"); var count = ls2.length; var strLink = ""; var optionItem; //Clear the previous options from the list for(var lstCount = strListBox.options.length-1; lstCount>-1; lstCount--) { strListBox.options[lstCount] = null; } if(count >= 2 ) { for(var x = count-1; x>=0; x--) { var ls3=ls2[x];//[x].split("|"); strLink+= ls3; optionItem = new Option(ls3, ls3, false, false); strListBox.options[strListBox.length] = optionItem; } } } } }

      Vishnu Narayan Mishra Software Engineer

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

      You didn't ask in the ASP.NET forum because.....

      Vishnu Narayan Mishra wrote:

      onChange

      It's all lowercase, I believe. onchange.

      Vishnu Narayan Mishra wrote:

      How can I set TextBox value from asp.net Listbox

      Your big issue will be that the names you give ASP.ENT controls on the server, are not the names they have on the client. Use the ClientID property to find the client side name, and pass that to the client so getElementById will work

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      V 1 Reply Last reply
      0
      • C Christian Graus

        You didn't ask in the ASP.NET forum because.....

        Vishnu Narayan Mishra wrote:

        onChange

        It's all lowercase, I believe. onchange.

        Vishnu Narayan Mishra wrote:

        How can I set TextBox value from asp.net Listbox

        Your big issue will be that the names you give ASP.ENT controls on the server, are not the names they have on the client. Use the ClientID property to find the client side name, and pass that to the client so getElementById will work

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        V Offline
        V Offline
        Vishnu Narayan Mishra
        wrote on last edited by
        #3

        Thanks sir for guidance, I have resolved my problem following is code.. in CS file i added this line .. lstShowHistory.Attributes.Add("onchange", "ShowText();"); and by javascript I set the value of textbox, but it works only on by selecting item from mouse. How can I select value from the listbox by arrow key of keyboard?? Have you any idea... function ShowText() { var txtMessage = document.getElementById('lstShowHistory').options[document.getElementById('lstShowHistory').selectedIndex].text;//GetComboText(document.getElementById('lstShowHistory')); document.getElementById('txtUrlLink').value = txtMessage; document.getElementById('helptypediv').style.visibility='hidden';return false; }

        Vishnu Narayan Mishra Software Engineer

        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