On 23 Oct 2003 15:49:48 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com > brought forth from the murky depths:
Thomas 'PointedEars' Lahn <Po*********@we b.de> writes:
Enclose the radio *buttons* in a `fieldset' element or leave them as
children of the `form' element. Use the `onchange' event handler of
either element
I didn't know that forms or fieldsets had onchange event handlers.
Checking the HTML 4.01 specification gives no mention of these.
I tested in IE 6, Opera 7 and Mozilla, using the following code:
---
<form onchange="alert ('form')" action="">
<fieldset onchange="alert ('field')"><leg end>Test</legend>
<input name="too" onchange="alert ('input')">
</fieldset>
</form>
---
and it threw all alerts in in Opera and Moz. In IE, only the input alert
was displayed.
Along the same line, I need to check for empty fields and am currently
using this script to do so. The problem is that it doesn't check radio
button fieldsets (or checkboxes). How would I add that in the simplest
way? All she wants me to check for are empties.
<SCRIPT LANGUAGE="JavaS cript">
<!-- Original: wsabstract.com -->
<!-- The JavaScript Source!!
http://javascript.internet.com -->
<!-- Begin
function checkrequired(w hich) {
var pass=true;
if (document.image s) {
for (i=0;i<which.le ngth;i++) {
var tempobj=which.e lements[i];
if (tempobj.name.s ubstring(0,1)== "x") {
if (((tempobj.type =="text"||tempo bj.type=="texta rea")&&
tempobj.value== '')||(tempobj.t ype.toString(). charAt(0)=="s"& &
tempobj.selecte dIndex==0)) {
pass=false;
break;
}
}
}
}
if (!pass) {
shortFieldName= tempobj.name.su bstring(2,30).t oUpperCase();
alert("Please make sure the "+shortFieldNam e+" field is completed.");
return false;
}
else
return true;
}
// End -->
</script>
I add an x to the fieldname and strip off both the prefix letters
and the x. EG: name="xdname" is a required deliver-to name.
Is there a simple way to add radio button checking?