473,614 Members | 2,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

6 New Member
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 40132
iam_clint
1,208 Recognized Expert Top Contributor
try checked=true
Mar 24 '07 #2
mrhoo
428 Contributor
I don't know why, but if you append the input element to the document first,you can then set the checked value:

cell1.appendChi ld(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 Recognized Expert Top Contributor
thats interesting never tried that.
Mar 24 '07 #4
ssh
6 New Member
I don't know why, but if you append the input element to the document first,you can then set the checked value:

cell1.appendChi ld(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 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
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 Recognized Expert Expert
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 Recognized Expert Expert
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.setAttribut e on my IE7 and they both work fine.
Mar 27 '07 #10

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

Similar topics

2
29331
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
7202
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 "Send", I see in my browser directory where the considered html source is located. If I publish the given html source, open published page and again press "Send" nothing changes... What I want to do, is to know what choice did people who were visiting...
4
1206
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
1055
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 there a way of making the readio button trigger a post back to the server whenever it is selcted?
4
1946
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 TemplateColumns is a checkbox. During the page's postback I loop over the DataGrid and read the checkbox values. My problem is, none of the checkboxes ever have their "Checked" attribute set-- it's as though anything I mark is ignored.
1
2841
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
4173
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 database. when a user clicks any of the above values and saves the form, the item's "value" is getting saved in database. and when a user logs back in, his/her previously checked value items should be shown as checked. Everything is working fine...
1
1128
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
6600
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 created via grdData_ItemDataBound with id="chkRecordId": Protected Sub grdData_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grdData.ItemDataBound If e.Item.ItemType <>...
0
8640
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8589
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8287
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8443
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7114
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6093
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5548
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4136
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.