473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

checkbox property "checked" working in FF but not in IE ... suggestions please ...

6
Expand|Select|Wrap|Line Numbers
  1.  function testfn(name) 
  2. var tbody = document.getElementById('hellospace').getElementsByTagName('tbody')[0];
  3.     var row = document.createElement('TR');
  4.     var cell1 = document.createElement('TD');
  5.     cell1.align="left";
  6.     cell1.style.height = "22";
  7.     cell1.style.width = "15";
  8.     cell1.valign = "middle";
  9.     cell1.className = "dwInfo";
  10.     var inp1 = document.createElement('INPUT');
  11.     inp1.type = "checkbox";
  12.     inp1.name = "collectionName";
  13.     inp1.value = name;
  14.     inp1.checked = "checked";
  15.  
  16.     cell1.appendChild(inp1);
  17.     //cell2
  18.     var cell2 = document.createElement('TD');
  19.     cell2.style.height = "22";
  20.     cell2.align ="left";
  21.     cell2.className = "dwInfo";
  22.     cell2.innerHTML= name ;
  23.     row.appendChild(cell1);
  24.     row.appendChild(cell2);
  25.     tbody.appendChild(row);     
  26.  
  27.  
All works find in firefox but in IE the checkbox property "checked" doesnt seem to be working.

Problem:
This function testfn(name) is used to append a row whenever a particular conditions check is true. So here in firefox when the function executes, a row is appended and also the checkbox is checked. In IE the row is appended but the checkbox is not checked.

It would be great if anyone could suggest where the problem could be.

Thanks in Advance,
ssh.
Mar 24 '07 #1
12 40104
iam_clint
1,208 Expert 1GB
try checked=true
Mar 24 '07 #2
mrhoo
428 256MB
I don't know why, but if you append the input element to the document first,you can then set the checked value:

cell1.appendChild(inp1);
inp1.checked = "checked";

This also seems to be needed by Opera, and it
will apply the value in firefox,which doesn't care, just as well.
Mar 24 '07 #3
iam_clint
1,208 Expert 1GB
thats interesting never tried that.
Mar 24 '07 #4
ssh
6
I don't know why, but if you append the input element to the document first,you can then set the checked value:

cell1.appendChild(inp1);
inp1.checked = "checked";

This also seems to be needed by Opera, and it
will apply the value in firefox,which doesn't care, just as well.

hi!
I tried both the ways already but couldnt get it working in IE. Anyway Thank you very much.

I also tried checked = "true" but still it doesnt work in IE. Need to find some other way to get it checked ...

Regards,
ssh
Mar 25 '07 #5
acoder
16,027 Expert Mod 8TB
There are two solutions to this:
  • Set the defaultChecked property instead.
  • Try
    Expand|Select|Wrap|Line Numbers
    1. inp1.setAttribute("checked","checked");
    after appending as suggested by mrhoo
See this link.
Mar 26 '07 #6
ssh
6
There are two solutions to this:
  • Set the defaultChecked property instead.
  • Try
    Expand|Select|Wrap|Line Numbers
    1. inp1.setAttribute("checked","checked");
    after appending as suggested by mrhoo
See this link.

Initially i used setAttribute but this 'setAttribute' doesnt work in IE7. It works only in ff.

Regards,
ssh
Mar 26 '07 #7
acoder
16,027 Expert Mod 8TB
Initially i used setAttribute but this 'setAttribute' doesnt work in IE7. It works only in ff.

Regards,
ssh
IE! Such a buggy browser!

Use the first option then:
Expand|Select|Wrap|Line Numbers
  1. inp1.defaultChecked=true
Mar 27 '07 #8
Atli
5,058 Expert 4TB
Initially i used setAttribute but this 'setAttribute' doesnt work in IE7. It works only in ff.

Regards,
ssh

This works fine for me in IE7.

Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" id="cb" />
  2. <br />
  3. <div onclick="javascript: getElementById('cb').setAttribute('checked', 'checked');">
  4. Linkage
  5. </div>
  6.  
Mar 27 '07 #9
Atli
5,058 Expert 4TB
For some weird reason the checked attribute can not be set before the input is appended to the cell.
So append it first and then check it.

I tested both var.checked and var.setAttribute on my IE7 and they both work fine.
Mar 27 '07 #10
acoder
16,027 Expert Mod 8TB
Initially i used setAttribute but this 'setAttribute' doesnt work in IE7. It works only in ff.

Regards,
ssh
It should work as confirmed by Atli. Post your new code.
Mar 28 '07 #11
'someCheckBox.checked' should work in IE if the element is inside a form and you access it through the forms collection:

document.forms.someForm.someCheckBox.checked


Diego
Sep 23 '10 #12
Expand|Select|Wrap|Line Numbers
  1. var checkbox = document.createElement('input');
  2. checkbox.setAttribute('type', 'checkbox');
  3. checkbox.setAttribute('name', 'elem_name');
  4. checkbox.setAttribute('id', 'elem_name');
  5. checkbox.setAttribute('value', 1);
  6. checkbox.setAttribute("checked", true);
  7. checkbox.checked    = "checked";
  8. checkbox.defaultChecked    = true;
  9.  
I've just met this kind of problem before, the above code segment works fine in IE6+,FF,Chrome
Jan 28 '11 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John E | last post by:
How do I get whether a checkbox is ticked in a form on a form's submission (true or false)? How do I use the Request object in ASP?
3
by: Kurda Yon | last post by:
Sorry for a very stupid question. Can you tell me what does the following html source does if I press button "Send"? If I read this code by Netscaspe from my local file system and then press...
4
by: Brett | last post by:
Why would you not want to use checked on any type of mathematical operation? Or use unchecked for that matter? Thanks, Brett
0
by: bredal Jensen | last post by:
Dear gurus, I have a "farm " of radio buttons server control in a table. I need to detect when the user has selected any of them( before any postback). i'm not quit sure how to do this. Is...
4
by: Jim Bancroft | last post by:
Hi everyone, I'm using a DataGrid with TemplateColumns. My DataGrid is located in a cell of an asp:Table. I did this so it's positioned correctly onscreen. One of the DataGrid's...
1
by: Samuel Chowdhuri | last post by:
this peace of code is giving me trouble DIM i as DataGridItem for each i in myDataGrid checkbox chkbox = Ctype(i.findcontrol("deletethis"),checkbox) if(chkbox.checked) then ...... .....
6
by: painkiller | last post by:
language: vb.net environment: windows forms .net : v1.1 i am having a checkedlistbox control that display document category such as text, image, video, audio etc. these values are coming from...
1
by: AliRezaGoogle | last post by:
Dear Members Hi, I have a question: Why doesn't "checked" work for sub calls? For example consider the following snippet of code: checked { Overflower(); }
4
by: uicouic | last post by:
Hi all. I need JavaScript to validate that atleast one checkbox has been checked in a form before the record(s) can be deleted. - I have an <asp:button id="btnDelete"...> and the checkbox is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.