JSchwarz
08-18-2003, 10:34 AM
I have some very simple JavaScript code which I want to execute whenever the user clicks a different radio button (from a set of three). However, the code seems to execute "one behind" whatever the user is doing (does that make sense?).
OK, here's one of my attempts:<INPUT TYPE=radio NAME="isPriceFactor" TABINDEX=37 VALUE="1" onChange="
getRatingInfo(getVal("isPriceFactor"));
">Price factor<BR>
<INPUT TYPE=radio NAME="isPriceFactor" TABINDEX=37 VALUE="2" onChange="
getRatingInfo(getVal("isPriceFactor"));
">Past Performance factor<BR>
<INPUT TYPE=radio NAME="isPriceFactor" TABINDEX=37 VALUE="0" CHECKED onChange="
getRatingInfo(getVal("isPriceFactor"));
">Neither
But the value of "isPriceFactor" always seems to be the *previously* checked value. That is, if isPriceFactor has value "Neither" checked, and the user clicks on "Price factor", then getVal("isPriceFactor") returns 0 -- the previous value (not the one the user just ckeched, which would be 1).
As you can see, I'm using the onChange event, but I've also tried the onBlur event.
Also, I need this to work for both IE and NN4 and for mouse and keyboard navigation.
Here is the (relevant) code for getVal(). I know this looks like a lot of code, but it's really simple <G>.
Thanks in advance if anyone can help.
Jeff
[CODE]function getVal(strFld) {
switch (type=getType(strFld)) {
case "hidden":
case "text":
case "textarea":
val = fld.value;
break;
case "select-one":
val = fld.options[fld.selectedIndex].value;
break;
case "select-multiple":
case "checkbox":
alert("Lazy programmer alert: Did not implement getFieldVal for " + type + " fields (yet).");
return;
break;
case "radio":
return isRadioChecked(fld);
break;
default:
alert("Stupid programmer alert: Has not heard of " + fld.type + " type fields");
return;
break;
} // switch (type=getType(strFld))
return val;
} // function getVal()
function getType(elName) {
for (var x=0; x<thisForm.length; x++) {
if (thisForm[x].name == elName) {
el = thisForm[x];
break;
}
} // for (var x=0; x<frm.length; x++)
return el.type;
}
function isRadioChecked(fld) {
// Returns false if fld -- a radio button field -- has no options checked, otherwise it returns the value of the checked option.
for (var i=0; i<fld.length; i++) {
if (fld[i].checked) return fld[i].value;
}
return false;
} // function isChecked(fld)
OK, here's one of my attempts:<INPUT TYPE=radio NAME="isPriceFactor" TABINDEX=37 VALUE="1" onChange="
getRatingInfo(getVal("isPriceFactor"));
">Price factor<BR>
<INPUT TYPE=radio NAME="isPriceFactor" TABINDEX=37 VALUE="2" onChange="
getRatingInfo(getVal("isPriceFactor"));
">Past Performance factor<BR>
<INPUT TYPE=radio NAME="isPriceFactor" TABINDEX=37 VALUE="0" CHECKED onChange="
getRatingInfo(getVal("isPriceFactor"));
">Neither
But the value of "isPriceFactor" always seems to be the *previously* checked value. That is, if isPriceFactor has value "Neither" checked, and the user clicks on "Price factor", then getVal("isPriceFactor") returns 0 -- the previous value (not the one the user just ckeched, which would be 1).
As you can see, I'm using the onChange event, but I've also tried the onBlur event.
Also, I need this to work for both IE and NN4 and for mouse and keyboard navigation.
Here is the (relevant) code for getVal(). I know this looks like a lot of code, but it's really simple <G>.
Thanks in advance if anyone can help.
Jeff
[CODE]function getVal(strFld) {
switch (type=getType(strFld)) {
case "hidden":
case "text":
case "textarea":
val = fld.value;
break;
case "select-one":
val = fld.options[fld.selectedIndex].value;
break;
case "select-multiple":
case "checkbox":
alert("Lazy programmer alert: Did not implement getFieldVal for " + type + " fields (yet).");
return;
break;
case "radio":
return isRadioChecked(fld);
break;
default:
alert("Stupid programmer alert: Has not heard of " + fld.type + " type fields");
return;
break;
} // switch (type=getType(strFld))
return val;
} // function getVal()
function getType(elName) {
for (var x=0; x<thisForm.length; x++) {
if (thisForm[x].name == elName) {
el = thisForm[x];
break;
}
} // for (var x=0; x<frm.length; x++)
return el.type;
}
function isRadioChecked(fld) {
// Returns false if fld -- a radio button field -- has no options checked, otherwise it returns the value of the checked option.
for (var i=0; i<fld.length; i++) {
if (fld[i].checked) return fld[i].value;
}
return false;
} // function isChecked(fld)