Maggie Blue said on 19/04/2006 1:53 AM AEST:
[...]
How would you check certain ones using the URL? I've seen that:
a page is linked to, e.g.:
http://somedomain.com/index.html?c1=y&c7=y
and on page load checkboxes with id=c1 and id=c7 are checked.
Use window.location.search which returns the ? and everything after it
from the URL.
<URL:http://developer.mozilla.org/en/docs/DOM:window.location#Properties>
In the above case:
var searchString = window.location.search.substring(1);
// searchString is now c1=y&c7=y
Split it on the '&' to get an array of the parts, then for each part
split on the '=' to get the name/id and flag.
var searchString = window.location.search.substring(1);
if ( /=/.test(searchString) ){
var nameVals = searchString.split('&');
var nameVal, el;
for (var i=0, len=nameVals.length; i<len; ++i){
nameVal = nameVals[i].split('=');
if ( nameVal[1].toLowerCase() == 'y'
&& (el = document.forms['fName'].elements[nameVal[0]])){
el.checked = true;
}
}
}
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>