Write value of JavaScript variable in HTML tag

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jessy
    New Member
    • Oct 2006
    • 106

    Write value of JavaScript variable in HTML tag

    i need to know if its possible to write the value of a Javascript variable inside HTML tag ..and here's the line :
    [CODE=javascript] var x=document.getE lementById('div 1').value;
    formdiv.innerHT ML = formdiv.innerHT ML +'<td align=center> java script variable x</td>'[/CODE]

    i need to write the value of this X between the tags and i tried thousands of solutions but none of them worked :(
    Last edited by gits; Nov 7 '08, 10:46 AM. Reason: added code tags
  • rnd me
    Recognized Expert Contributor
    • Jun 2007
    • 427

    #2
    2 things:

    1. div tags have no .value; use .innerHTML

    2. TDs cannot be inserted via innerHTML in IE, you have to use dom methods...

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      2 more things:

      1. "is it possible or not plz i need an answer !" is not a good title, so I've changed it to something more appropriate. Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

      This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions. Thanks!

      2. To include the variable within tags, e.g. <span>:
      Code:
      formdiv.innerHTML += '<span>' + x + '</span>';

      Comment

      • jessy
        New Member
        • Oct 2006
        • 106

        #4
        Oh My God
        thanks so Much "acoder"

        You people in Bytes are Wonderful !!!!!

        sorry for the !! ;)

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Glad to hear so. Make sure you look at the other points too :)

          Comment

          Working...