...

View Full Version : Adding text based on form input



PureMisery
10-27-2006, 04:00 AM
This is my first time trying to code something with JavaScript.

Basicly I have a form with a checkbox, if the user checks the box some extra html code is added to the page. I did some googling and reading on displaying text with JavaScript but I can't seem to get this working.



<html>
<head>
<title>Test</title>
</head>

<body bgcolor="#000000" text="#FFFFFF">

<script type="text/javascript">
function checkResults (form) {
var checkVar = form.check1.value;
if(checkVar)
document.writeln("<div style=\"position:absolute; left:302; top:288;\"><a href=\"timeline.html#week1\"><img src=\"marker.jpg\" style=\"border:none;\"></a></div>");
}
</script>

<img src="map1_shrink2.jpg" alt="Main Map"><br>

<FORM NAME="myform" ACTION="" METHOD="GET">
Mark 1:<input type="checkbox" name="check1" onclick="checkResults(this.form)">
</FORM>

</body>
</html>


With that code, when I click the checkbox the page reloads and displays the extra html but nothing else is there and the page never finishes loading.

The ultimate goal of this page is a map. The user will be able to check different boxes which will add route overlays.

Can someone point out what's wrong with this code or point me into a better direction of doing this (other than server side languages)?

gunman
10-27-2006, 07:43 AM
Instead of using

document.writeln you could use

innerHtml property of choosen object you could find some more information about it at http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/innerhtml.asp



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum