...

View Full Version : onLoad and onchange affect each other



kamkam
03-15-2009, 05:17 AM
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.






<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<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
// http://simonwillison.net/2004/May/26/addLoadEvent/
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>

kamkam
03-15-2009, 05:58 AM
Thanks for come here, i have known the solution already.

replace


Code:
addLoadEvent(function() {
setStates();
});
with

Code:
addLoadEvent(function() {
setStates();
checkCookie();
});



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum