F
frogman042
My daughter is playing around trying to learn JavaScript and she wrote
a small program that prints out a message in increasing and decreasing
font size and color changes. She is using document write and it works
fine until she puts it into a function and then calls the function from
a button with onClick. This also seems to work OK, with the exception
that the page is cleared, and the curser changes (and stays) as an
hourglass.
In reading some threads it seems that after the page is loaded,
subsequent calls to document.write cause the page to clear, so only
output is written and the button is lost.
In essence is there a way to do the following:
Have a input text filed and a button. Clicking the button writes out
formatted html below it. Clicking it again rewrites it out with new
values depending on the value in the input text.
Any ideas on how to do this easily would be appreciated.
Thanks in advance.
---Jay
Here is the code she wrote:
<html>
<script type="text/javascript">
function coolJulie (firstval, big, small){
var i = firstval
while (i < big) {
document.write("<center><font size= "+ i +" color=" + i * i * i * i *
109684 + ">You Just Typed in: " + document.myForm.hi.value +
"</center></font><BR>");
i = i + 1
}
while (i > small) {
document.write("<center><font align=center size= "+ i +" color=" + i
* i * i * i * 109684 + ">You Just Typed in: " +
document.myForm.hi.value + "</center></font><BR>");
i = i - 1
}
}
</script>
<body>
<form name='myForm'>
<br><br>
<center>
<b>
<font size=3 color='red'>Hi I'm so cooler then some people, maybe even
you!</font>
<br>
<input type=text name='hi' value='yoohoo'>
<input type=button name="ClickMe" value= 'Click Here if you're done
typing' onClick='coolJulie(1,5,1);'>
</form>
</body>
</html>
a small program that prints out a message in increasing and decreasing
font size and color changes. She is using document write and it works
fine until she puts it into a function and then calls the function from
a button with onClick. This also seems to work OK, with the exception
that the page is cleared, and the curser changes (and stays) as an
hourglass.
In reading some threads it seems that after the page is loaded,
subsequent calls to document.write cause the page to clear, so only
output is written and the button is lost.
In essence is there a way to do the following:
Have a input text filed and a button. Clicking the button writes out
formatted html below it. Clicking it again rewrites it out with new
values depending on the value in the input text.
Any ideas on how to do this easily would be appreciated.
Thanks in advance.
---Jay
Here is the code she wrote:
<html>
<script type="text/javascript">
function coolJulie (firstval, big, small){
var i = firstval
while (i < big) {
document.write("<center><font size= "+ i +" color=" + i * i * i * i *
109684 + ">You Just Typed in: " + document.myForm.hi.value +
"</center></font><BR>");
i = i + 1
}
while (i > small) {
document.write("<center><font align=center size= "+ i +" color=" + i
* i * i * i * 109684 + ">You Just Typed in: " +
document.myForm.hi.value + "</center></font><BR>");
i = i - 1
}
}
</script>
<body>
<form name='myForm'>
<br><br>
<center>
<b>
<font size=3 color='red'>Hi I'm so cooler then some people, maybe even
you!</font>
<br>
<input type=text name='hi' value='yoohoo'>
<input type=button name="ClickMe" value= 'Click Here if you're done
typing' onClick='coolJulie(1,5,1);'>
</form>
</body>
</html>