PDA

View Full Version : country error javascript



crunkbbfe
Jun 22nd, 2007, 05:30 PM
I am having an error with this script

the error printed onto the error console is
"document.forms[0].country has no properties"


here is the javascript


<script type="text/javascript">
function check(){
if(document.forms[0].country.value!="usa"){
document.getElementById('other').innerHTML='<br><input type="text" name="other" value="Enter Country Name" size="20" onfocus="if(this.value==\'Enter Country Name\'){this.value=\'\';}">';
}
else {
document.getElementById('other').innerHTML='';
}
}
</script>




and then here is the form up to where i would like something to occur




<form action="member.php" method="post">
<table><tr><Td>First Name:</td><Td><input type="text" name="fname"></td></tr>
<tr><Td>Last Name:</td><Td><input type="text" name="lname"></td></tr>
<tr><Td>City:</td><td><input type="text" name="city"></td></tr>
<tr><Td>Zip/Postal Code:</td><td><input type="text" name="zipcode" maxlength="12"><td></tr>
<tr><Td>
Country: </td><td><select name="country" onchange="check()"><option>Select one:</option>
<?
$state = mysql_Query("SELECT * FROM country ORDER BY country");
while($sta=mysql_fetch_array($state)){
echo "<option value='".$sta['id']."'>".$sta['country']."</option>";
}
?>
</select><span id="other"></span>
</select>

glenngv
Jun 23rd, 2007, 10:06 AM
Is that the first form? You might have other form in your page. Anyway, this can be easily solved by passing the keyword this to refer to the dropdown itself.

function check(sel){
if (sel.value!="usa"){
...

<select name="country" onchange="check(this)">