Closed Bug 327020 Opened 18 years ago Closed 18 years ago

.setAttribute("checked", true) don't work allways.. But .checked=true; works

Categories

(Core :: DOM: Core & HTML, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 223003

People

(Reporter: adrenalinup, Unassigned)

Details

Attachments

(1 file)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1

setAttribute('checked',true); in some situation don't work.
I had multiple checkbox what must be all checked on "check all" button click(using setAttribute('checked',true)), but if user deselect one, and click again on "check all", the manual unchecked checkbox, didn't want anymore to be checked.
If instead of .setAttribute('checked',true), i use .checked=true, all works as supposed.
The IE&Opera also don't have this bug.

Reproducible: Always

Steps to Reproduce:
1. Click on check all
2. Unselect a checkbox
3. Click again on "check all"

Actual Results:  
The manual unchecked checkbox, after "check all", remain unchecked

Expected Results:  
The manual unchecked checkbox, after "check all", must be also checked.
Attached file Testcase
Comment on attachment 211736 [details]
Testcase

><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
><HTML><HEAD><TITLE>Title</TITLE></HEAD><BODY>
>(click on "check all" button, after, uncheck a chk, and click again on "check all", it don't seem to check the manual unchecked checkbox..)<BR/>
><INPUT type="button" value="Check all" onclick="checkall();"/>
><DIV id="checkboxs">
><INPUT type="checkbox"/>Chk1
><INPUT type="checkbox"/>Chk2
><INPUT type="checkbox"/>Chk3
></DIV>
><SCRIPT type="text/javascript">
>function checkall() {
>  inputs = document.getElementById('checkboxs').getElementsByTagName('input');
>  var i;
>  for (i=0;i&lt;inputs.length;i++) {
>    inputs[i].setAttribute('checked',true);
>    //inputs[i].checked=true; //With this way to check, no bugs, all work as supposed..
>  }
>}
></SCRIPT>
></BODY></HTML>
Attachment #211736 - Attachment is obsolete: true
Attachment #211736 - Attachment is obsolete: false
Yes, that's the difference between the dom property .checked and the attribute checked.
This is not a bug.

*** This bug has been marked as a duplicate of 223003 ***
Status: UNCONFIRMED → RESOLVED
Closed: 18 years ago
Resolution: --- → DUPLICATE
(In reply to comment #3)
> Yes, that's the difference between the dom property .checked and the attribute
> checked.
> This is not a bug.
> 
> *** This bug has been marked as a duplicate of 223003 ***
> 

It's odd, and i think this will cause confusion to the web developers in future..
FF should act like other browsers..
Status: RESOLVED → UNCONFIRMED
Resolution: DUPLICATE → ---
> It's odd, and i think this will cause confusion to the web developers in
> future..

"Changes to this [checked] attribute change the state of the form control, but do not change the value of the HTML checked attribute of the INPUT element."
http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-30233917

If you replace in attachment 211736 [details] this line:

inputs[i].setAttribute('checked',true);

with these 4 lines:

  if(!inputs[i].checked)
  {
  inputs[i].click();
  };

then you'll get the expected results in all browsers (Seamonkey 1.x, Firefox 1.x, IE 7 beta 2, Opera 9, etc.)

Resolving as DUPLICATE of bug 223003

*** This bug has been marked as a duplicate of 223003 ***
Status: UNCONFIRMED → RESOLVED
Closed: 18 years ago18 years ago
Resolution: --- → DUPLICATE
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: