beetle's fValidate is pretty amazing; it's about the closest thing you'll find to a really portable, full-featured client-side form processing script around. Don't know if it does the specific behavior you cited (really more of a convenience feature than an input checker) but, if it doesn't, he's probably working on one as we speak. Pretty easy to write, actually:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">
function too_lazy_to_populate()
{
var oForm = document.forms[0];
oForm.elements['bill_name'].value = 'Milton Knish';
oForm.elements['bill_street'].value = '33 Hellish Crescent';
oForm.elements['bill_city'].value = 'Homer';
oForm.elements['bill_state'].value = 'AK';
oForm.elements['bill_zip'].value = '99989';
}
function is_same_as_bill(oCheckbox)
{
var oForm = oCheckbox.form;
var bWhich = oCheckbox.checked;
var fields = ['name' , 'street' , 'city' , 'state' , 'zip'];
for (var i = 0; i < fields.length; ++i)
{
oForm.elements['ship_' + fields[i]].value = (bWhich) ? oForm.elements['bill_' + fields[i]].value : '';
oForm.elements['ship_' + fields[i]].readOnly = (bWhich) ? true : false;
}
if (!bWhich)
oForm.elements['ship_name'].focus();
return true;
}
</script>
</head>
<body>
<form>
<input type="button" value="do it for me"
onclick="too_lazy_to_populate()"><br /><br />
<h5>Billing Address</h5>
<input id="bill_name" name="bill_name" value="" type="text">____name<br />
<input id="bill_street" name="bill_street" value="" type="text">____street address<br />
<input id="bill_city" name="bill_city" value="" type="text">____city<br />
<input id="bill_state" name="bill_state" value="" type="text">____state<br />
<input id="bill_zip" name="bill_zip" value="" type="text">____zip code<br />
<h5>Shipping Address / check if same as Billing Address____<input type="checkbox"
onclick="return is_same_as_bill(this)"></h5>
<input id="ship_name" name="ship_name" value="" type="text">____name<br />
<input id="ship_street" name="ship_street" value="" type="text">____street address<br />
<input id="ship_city" name="ship_city" value="" type="text">____city<br />
<input id="ship_state" name="ship_state" value="" type="text">____state<br />
<input id="ship_zip" name="ship_zip" value="" type="text">____zip code<br />
</form>
</body>
</html>
Problem is, other enabling/disabling/write-preventing/whatever scenarios can become pretty application-specific, necessitating some custom code. Anything can be generalized, of course, if you have the time. Might check here.
Bookmarks