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
    Tjk
    Tjk is offline
    New Coder
    Join Date
    Aug 2005
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Basic form evaluating

    Code:
       <script type="text/javascript">
       <!--   
       function view(){
         city= document.map.city.value;
         town= document.map.town.value;
         fort= document.map.fort.value;
         if(city.checked){
    	     document.map.cityval.value = 1;
         }
       }
       -->
       </script>
       <body>
       <form name="map" method="POST" action="gamemap.php">
       <p><input type="radio" name="city" id="city" onclick="view()"> City</p>
       <p><input type="text" length="3" name="cityval" id="cityval"> City Value</p>
       </form>
       </body>
    I'm trying to get this script to write a value of 1 to cityval when the radio city is clicked but the script doesn't do anything at all. Could anyone tell me why this is?

    Thanks in advance for any help.

  • #2
    New Coder
    Join Date
    Aug 2006
    Posts
    66
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    <script type="text/javascript">
    
    function view()
    {
    	var allElements = document.getElementsByTagName('*'); 
    	for(var i=0; i < allElements.length; i++)
    	{
    		var currentElement = allElements[i]; var elementId = currentElement['id']; 
    		if(elementId=="city") { var city = currentElement; }
    		if(elementId=="cityval") { var cityval = currentElement; } 
    	}
    	
    	if(cityval.value=="" || cityval.value==null) { cityval.value='1'; } else { cityval.value=''; } 
    }
    </script>
    
       <body>
       <form name="map" method="POST" action="gamemap.php">
       <p><input type="radio" name="city" id="city" onclick="view()"> City</p>
       <p><input type="text" length="3" name="cityval" id="cityval"> City Value</p>
       </form>
       </body>


  •  

    Posting Permissions

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