omgwtf
09-09-2004, 10:28 PM
I have a weird problem that maybe someone here can help me with. I'm writing a large PHP web based application which includes some javascript for added functionality. My problem is that when a certain form (comprised of radio buttons and checkboxes) used to edit or delete items from the database is submitted using the Edit button :
<input type=\"radio\" name=\"edit\" value=\"$eventnum\">
<input type=hidden name=\"numres\" value=\"\">
<input type=hidden name=\"eventid\" value=\"\">
<input name=\"eventaction\" value=\"Edit\" type=\"submit\" onClick=\"return editev($num);\">
the editev() javascript function called by onClick generally works, but only if the form contains 2 or more objects. If the function is called with only one object in the list, e.g. onClick editev(1); then document.eventm.edit[i] returns undefined instead of the object referred to. But.. when 2 or more objects are submitted to the javascript function, all objects are identified correctly with no "undefined"s
here is the javascript function:
function editev(rnum){
var n = 0;
for(i = 0; i < rnum; i++){
//following 2 lines are for debugging problem
rval = document.eventm.edit[i];
alert(\"i is = \" + i + \" and \" + rval);
if (isChecked(document.eventm.edit[i])){
n++;
}
}
if (n == 0) {
alert(\"No events have been selected!\");
return false;
} else if (n == 1) {
document.eventm.numres.value = n;
return true;
}
}
Please help!
<input type=\"radio\" name=\"edit\" value=\"$eventnum\">
<input type=hidden name=\"numres\" value=\"\">
<input type=hidden name=\"eventid\" value=\"\">
<input name=\"eventaction\" value=\"Edit\" type=\"submit\" onClick=\"return editev($num);\">
the editev() javascript function called by onClick generally works, but only if the form contains 2 or more objects. If the function is called with only one object in the list, e.g. onClick editev(1); then document.eventm.edit[i] returns undefined instead of the object referred to. But.. when 2 or more objects are submitted to the javascript function, all objects are identified correctly with no "undefined"s
here is the javascript function:
function editev(rnum){
var n = 0;
for(i = 0; i < rnum; i++){
//following 2 lines are for debugging problem
rval = document.eventm.edit[i];
alert(\"i is = \" + i + \" and \" + rval);
if (isChecked(document.eventm.edit[i])){
n++;
}
}
if (n == 0) {
alert(\"No events have been selected!\");
return false;
} else if (n == 1) {
document.eventm.numres.value = n;
return true;
}
}
Please help!