...

View Full Version : Basic form evaluating



Tjk
10-31-2006, 09:40 PM
<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. :)

ruggeddesign
10-31-2006, 10:06 PM
<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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum