467,858 Members | 1,693 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,858 developers. It's quick & easy.

Insert javascript variable value in body of HTML page

Hello:

is it possible to insert the value of some JavaScript variable in the
body of HTML (for example the text on button, or at any part of the
HTML text part). Please tell me how to do this.

Thanks

Oct 18 '05 #1
  • viewed: 3035
Share:
4 Replies
VK

ke**************@yahoo.com wrote:
is it possible to insert the value of some
JavaScript variable in the body of HTML
(for example the text on button
<script type="text/javascript">
function myFunction() {
document.forms[0].elements[0].value = 'Custom text';
// or:
// document.myForm.button001.value = 'Custom text';
// which does the same
}
</script>
<body onload="myFunction()">
....
<form name="myForm">
<input type="button" name="button001" value="Default text">
</form>
....
, or at any part of the HTML text part).


To *change* the content of a text block see
<http://www.jibbering.com/faq/#FAQ4_15> and related links.

To *insert/replace* some text of a text block, you need to use
TextRange
object
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/obj_textrange.asp>
but it flyes as expected for IE only.
For other browser you need to use different legacy tricks. As these
tricks are numerous and their set/implementation depends heavily on
current tack, more clarification of your actual aim would be helpful.

Oct 18 '05 #2
See "InnerText" & "InnerHTML" properties for HTML objects and "value"
property for forms inputs.

Best, Ed.

Oct 18 '05 #3
Gomolyako Eduard wrote:
See "InnerText" & "InnerHTML" properties for HTML objects and "value"
property for forms inputs.

Best, Ed.

InnerText ? perhaps you mean: "innerText"?
The former doesn't exist, and the latter is unreliable(IE invention).
Mick
Oct 18 '05 #4
Mick White писал(а):
Gomolyako Eduard wrote:
See "InnerText" & "InnerHTML" properties for HTML objects and "value"
property for forms inputs.

Best, Ed.
InnerText ? perhaps you mean: "innerText"?


Yes, u right, i mean "innerText".
The former doesn't exist, and the latter is unreliable(IE invention).
Thx.
Mick


Oct 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.