Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding text based on form input

    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.

    Code:
    <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)?

  • #2
    New Coder
    Join Date
    Jul 2005
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/a.../innerhtml.asp
    If you can not find a decision, maybe you have to try to change a problem

    http://www.gunman.co.nr
    http://bglinux.org


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •