Forum Moderators: open

Message Too Old, No Replies

Javascript works in IE but fails in Firefox

         

jalperin

4:21 pm on Mar 21, 2005 (gmt 0)

10+ Year Member



I have a simple function which is supposed to check a checkbox in a form when a button is pressed. It works fine in IE, but nothing happens in Firefox. When checking the JavaScript console in Firefox, I see the following error: this.update_code_form has no properties

Here's the Javascript function:

function checktheboxes(whichbutton){
if (whichbutton == "approval"){
this.update_code_form.reviewcopy.checked=true;
this.update_code_form.mail_reviewers.checked=true;
this.update_code_form.finalize.checked=false;
this.update_code_form.email.checked=true;
this.update_code_form.samplecopy.checked=false;
} else if (whichbutton == "publish"){
this.update_code_form.reviewcopy.checked=false;
this.update_code_form.mail_reviewers.checked=false;
this.update_code_form.finalize.checked=true;
this.update_code_form.email.checked=true;
this.update_code_form.samplecopy.checked=true;
} else if (whichbutton == "clear"){
this.update_code_form.reviewcopy.checked=false;
this.update_code_form.mail_reviewers.checked=false;
this.update_code_form.finalize.checked=false;
this.update_code_form.email.checked=false;
this.update_code_form.samplecopy.checked=false;
}
}

The form is named update_code_form.

--Jeff

kaled

10:01 pm on Mar 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just a guess, but try :-

if (whichbutton.value == 'approval')

etc.

Kaled.

jalperin

10:24 pm on Mar 21, 2005 (gmt 0)

10+ Year Member



I don't think that's it. The line number of the Javascript error is different depending on which button is pressed, indicating that the conditional statement is working properly. I think the problem is with the this.update_code_form.[checkbox name].checked=true statement. There must be some sort of difference in how to refer to form elements in Firefox vs. IE. Does anyone know?

jalperin

12:05 am on Mar 22, 2005 (gmt 0)

10+ Year Member



Solution:

The references to the form elements need to be like this:

document.forms['update_code_form'].elements['samplecopy'].checked=false;

This seems to work in both IE and Firefox.