Insert javascript variable value in body of HTML page

K

keerthana_m_2003

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
 
V

VK

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">
, 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/d...hor/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.
 
G

Gomolyako Eduard

See "InnerText" & "InnerHTML" properties for HTML objects and "value"
property for forms inputs.

Best, Ed.
 
M

Mick White

Gomolyako said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top