how to pass some text to Label in the page using javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • indianmaestro
    New Member
    • Mar 2008
    • 16

    #1

    how to pass some text to Label in the page using javascript

    Hi
    i want to display some text on the label when i select an item int he listbox.
    for this i have written some code which is workint fine in the InternetEplore but when it comes to mozilla the text not showing

    my coding is like this

    document.getEle mentById('<%=lb lcnt.ClientID%> ').innerText="1 Student(s) selected";

    help me
  • enggwaqas
    New Member
    • Jun 2007
    • 19

    #2
    Originally posted by indianmaestro
    Hi
    i want to display some text on the label when i select an item int he listbox.
    for this i have written some code which is workint fine in the InternetEplore but when it comes to mozilla the text not showing

    my coding is like this

    document.getEle mentById('<%=lb lcnt.ClientID%> ').innerText="1 Student(s) selected";

    help me
    Try
    document.getEle mentById('<%=lb lcnt.ClientID%> ').innerHTML
    instead

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by indianmaestro
      Hi
      i want to display some text on the label when i select an item int he listbox.
      for this i have written some code which is workint fine in the InternetEplore but when it comes to mozilla the text not showing

      my coding is like this

      document.getEle mentById('<%=lb lcnt.ClientID%> ').innerText="1 Student(s) selected";

      help me
      When you're adding items to your ListBox, set the ListItem's onClick attribute to execute the JavaScript that will display the text in the text box:

      .NET code
      [code=vbnet]
      //populating list
      With MyListBox.Items
      .Add(New ListItem("ItemA ","text for A"))
      .Add(New ListItem("ItemB ","text for B"))
      .Add(New ListItem("ItemC ","text for C"))
      End With
      [/code]

      [code=vbnet]
      For Each li As ListItem In RBtnL_DateOptio ns.Items
      li.Attributes.A dd("onclick", "JavaScript : displayText('"+ myLabel.ClientI D+"','"+li.Attr ibutes.Add("onc lick", li.Text)+"');")
      Next
      [/code]


      Then write a the JavaScript function that displays the text:

      [code=JavaScript]
      function displayText(lab elID,textValue)
      {/*something like*/
      document.getEle mentById(labelI D).value = textValue;
      }
      [/code]

      See How to check if a textbox contains a number for instructions on how to add the JavaScript to the browser using .NET.

      -Frinny

      Comment

      Working...