- function testfn(name)
-
var tbody = document.getElementById('hellospace').getElementsByTagName('tbody')[0];
-
var row = document.createElement('TR');
-
var cell1 = document.createElement('TD');
-
cell1.align="left";
-
cell1.style.height = "22";
-
cell1.style.width = "15";
-
cell1.valign = "middle";
-
cell1.className = "dwInfo";
-
var inp1 = document.createElement('INPUT');
-
inp1.type = "checkbox";
-
inp1.name = "collectionName";
-
inp1.value = name;
-
inp1.checked = "checked";
-
-
cell1.appendChild(inp1);
-
//cell2
-
var cell2 = document.createElement('TD');
-
cell2.style.height = "22";
-
cell2.align ="left";
-
cell2.className = "dwInfo";
-
cell2.innerHTML= name ;
-
row.appendChild(cell1);
-
row.appendChild(cell2);
-
tbody.appendChild(row);
-
-
}
-
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.
12 40104
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.
thats interesting never tried that.
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
There are two solutions to this: - Set the defaultChecked property instead.
- Try
- inp1.setAttribute("checked","checked");
after appending as suggested by mrhoo
See this link.
There are two solutions to this:- Set the defaultChecked property instead.
- Try
- 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
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: 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. -
<input type="checkbox" id="cb" />
-
<br />
-
<div onclick="javascript: getElementById('cb').setAttribute('checked', 'checked');">
-
Linkage
-
</div>
-
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.
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.
'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
-
var checkbox = document.createElement('input');
-
checkbox.setAttribute('type', 'checkbox');
-
checkbox.setAttribute('name', 'elem_name');
-
checkbox.setAttribute('id', 'elem_name');
-
checkbox.setAttribute('value', 1);
-
checkbox.setAttribute("checked", true);
-
checkbox.checked = "checked";
-
checkbox.defaultChecked = true;
-
I've just met this kind of problem before, the above code segment works fine in IE6+,FF,Chrome
Sign in to post your reply or Sign up for a free account.
Similar topics
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?
|
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...
|
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
|
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...
|
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...
|
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
......
.....
|
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...
|
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();
}
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |