Forum Moderators: open
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
.style4 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
.center-align { text-align:center; }
</style>
<script type="text/javascript">
window.onload = function() { attachBehaviors(); };
function attachBehaviors() {
if (document.getElementById('form1')) {
document.getElementById('form1').onsubmit=function() { return validateForm(this); };
}
if (document.getElementById('Select1')) {
document.getElementById('Select1').onchange=function() { get(this,this.form); };
}
}
//
function get(selectObj,form) {
var ind = selectObj.selectedIndex;
if (ind==0) {
form.airport.value='';
form.state.value='';
return;
}
var N = selectObj.options[ind].value;
var airports = {
1:"JFK",
2:"O'Hare",
3:"Logan",
4:"McCarran"
};
var states = {
1:"NY",
2:"IL",
3:"MA",
4:"NV"
};
if (N && (N>0)) {
form.airport.value=airports[N];
form.state.value=states[N];
}
}
//
function validateForm(form) {
// return false on errors, true if no errors.
// returning false in this placeholder so it
// doesn't submit.
alert('You submitted form.');
return false;
}
</script>
</head>
<body>
<form action="" name="form1" id="form1">
<p>
<select name="drop1" id="Select1">
<option value="0">Select</option>
<option value="1">NYC</option>
<option value="2">Chicago</option>
<option value="3">Boston</option>
<option value="4">Las Vegas</option>
</select>
</p>
<table width="323" border="0" class="style4">
<tr>
<td height="35" class="center-align">Airport</td>
<td class="center-align">State</td>
</tr>
<tr>
<td width="107" height="35" class="center-align">
<input name="airport" id="airport" type="text" value="" size="12" maxlength="12">
</td>
<td width="206" class="center-align">
<input name="state" id="state" type="text" value="" size="20" maxlength="15">
</td>
</tr>
<tr><td colspan="2" class="center-align">
<input type="submit" value="Test Validate Function">
</td></tr>
</table>
<p> </p>
</form>
</body>
</html>