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

Insert javascript variable value in body of HTML page

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
See "InnerText" & "InnerHTML" properties for HTML objects and "value"
property for forms inputs.

Best, Ed.

Oct 18 '05 #3

P: n/a
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

P: n/a
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.