By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,747 Members | 1,352 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,747 IT Pros & Developers. It's quick & easy.

Write value of JavaScript variable in HTML tag

P: 106
i need to know if its possible to write the value of a Javascript variable inside HTML tag ..and here's the line :
Expand|Select|Wrap|Line Numbers
  1.   var x=document.getElementById('div1').value;
  2.  formdiv.innerHTML = formdiv.innerHTML +'<td align=center> java script variable x</td>'
i need to write the value of this X between the tags and i tried thousands of solutions but none of them worked :(
Nov 7 '08 #1
Share this Question
Share on Google+
4 Replies

rnd me
Expert 100+
P: 427
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...
Nov 7 '08 #2

Expert Mod 15k+
P: 16,027
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>:
Expand|Select|Wrap|Line Numbers
  1. formdiv.innerHTML += '<span>' + x + '</span>';
Nov 7 '08 #3

P: 106
Oh My God
thanks so Much "acoder"

You people in Bytes are Wonderful !!!!!

sorry for the !! ;)
Nov 7 '08 #4

Expert Mod 15k+
P: 16,027
Glad to hear so. Make sure you look at the other points too :)
Nov 7 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.