xbl12
Programmer
- Dec 12, 2006
- 66
Hi;
I'd like to ask why the onLoad and onchange affect eachother ? How i can avoide that ?
<body onLoad="checkCookie()">
and
<select name="province_state_territories" id="state" onchange="setCities();">
when i use the above at the same time, the search function have not another option to choise. It means the option for selection
have not values.
Could anyone help me please, Thanks.
Because i want to use the "<body onLoad="checkCookie()">" to check my cookie and decide which Language i will use.
I'd like to ask why the onLoad and onchange affect eachother ? How i can avoide that ?
<body onLoad="checkCookie()">
and
<select name="province_state_territories" id="state" onchange="setCities();">
when i use the above at the same time, the search function have not another option to choise. It means the option for selection
have not values.
Could anyone help me please, Thanks.
Because i want to use the "<body onLoad="checkCookie()">" to check my cookie and decide which Language i will use.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html>
<head>
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8">
<script type="text/javascript">
// State lists
var states = new Array();
states['Australia'] = new Array('New South Wales');
// City lists
var cities = new Array();
cities['Australia'] = new Array();
cities['Australia']['New South Wales'] = new Array('Sydney');
function setStates() {
cntrySel = document.getElementById('country');
stateList = states[cntrySel.value];
changeSelect('state', stateList, stateList);
setCities();
}
function setCities() {
cntrySel = document.getElementById('country');
stateSel = document.getElementById('state');
cityList = cities[cntrySel.value][stateSel.value];
changeSelect('city', cityList, cityList);
}
function changeSelect(fieldID, newOptions, newValues) {
selectField = document.getElementById(fieldID);
selectField.options.length = 0;
for (i=0; i<newOptions.length; i++) {
selectField.options[selectField.length] = new Option(newOptions[i], newValues[i]);
}
}
// Multiple onload function created by: Simon Willison
// [URL unfurl="true"]http://simonwillison.net/2004/May/26/addLoadEvent/[/URL]
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(function() {
setStates();
});
</script>
</head>
<body onLoad="checkCookie()">
<form name="search_form" id="sf" action="search_p1.php" method="get">
<div>
<span class="search_form">Country:</class>
<select name="country" id="country" onchange="setStates();">
<option value="Australia">Australia</option>
</select>
<span class="search_form">State:</class>
<select name="province_state_territories" id="state" onchange="setCities();">
<option value="">please choose a state</option>
</select>
<br>
<span class="search_form">City:</class>
<select name="city" id="city">
<option value="">please choose a city</option>
</select>
<input type="submit" name="search_submit" value="search"></div>
</form>
</body>
</html>