Click to See Complete Forum and Search --> : innerHTML
aurelian65
08-01-2003, 08:01 AM
Hello,
I have a form with one hidden field and i want to copy the field's value into a span element (innerHTML) when document is loaded (onload); how can i do this? Please help!
Try this out:
<script type="text/javascript">
function moveVals() {
document.getElementById("myspan").innerHTML = document.myform.myfield.value;
}
window.onload = moveVals;
</script>
</head>
<body>
<form name="myform">
<input type="hidden" name="myfield" value="Your text">
</form>
<span id="myspan"></span>
aurelian65
08-04-2003, 02:39 AM
Hello pyro , and thank you! Your code works great and is really VERY simple, exactly what I needed. :)
SearedIce
08-04-2003, 09:28 AM
Hey thats interesting. I didn't know you could set up Event Handlers in Javascript. Pyro, tell me more about how this is done for stuff other than <body> etc. :)
Could you explain what you are asking a bit better, please?
SearedIce
08-04-2003, 11:33 AM
:) sorry
window.onload = moveVals;
I'm assuming that's the same as
<body onload="moveVals()">
now...i did not know you could activate event handlers by using javascript ("window.onload = moveVals;")
what is the format to follow for assigning event handlers for other things like say, images
<img name="img1">
<script type="text/javascript">
img1.onMouseOver = moveVals;
</script>
like would that be correct?
It's close... You need something more like this (remember that javascript is case sensative):
<img src="test.gif" name="img1">
<script type="text/javascript">
function test() {
alert ("testing");
}
document.img1.onmouseover = test;
</script>