I'm basically using AJAX and returning a bunch of information through XML and creating a checkbox. If the the XML returns that the checkbox should be set to true, check it, otherwise leave it empty. Below is my iteration when i go through the xml document. also i'd like to have the checkbox call a function when clicked, but I can't get it to work in both IE & Mozilla. Thanks for the help. - var chkbox = document.createElement('input');
-
chkbox.type='checkbox';
-
chkbox.setAttribute('name','chkPortfolio');
-
chkbox.setAttribute('id',"chkPortfolio_" + (j+1));
-
chkbox.setAttribute('value',portfolios.childNodes[j].firstChild.data);
-
if( portfolios.childNodes[j].attributes[1].text=="True") {
-
chkBox.onclick= function(evt) { refCell.set
-
}
-
else {
-
chkbox.checked=false;
-
}
-
chkbox.id = "chkPortfolio_" + (j+1);
-
chkbox.li_id = "trPortfolio_" + (j+1);
-
var name = document.createTextNode(portfolios.childNodes[j].firstChild.data);
-
listItem.appendChild(chkbox);
-
listItem.appendChild(name);
-
list.appendChild(listItem);
-
}
12 9589
I'm basically using AJAX and returning a bunch of information through XML and creating a checkbox. If the the XML returns that the checkbox should be set to true, check it, otherwise leave it empty. Below is my iteration when i go through the xml document. also i'd like to have the checkbox call a function when clicked, but I can't get it to work in both IE & Mozilla. Thanks for the help. - var chkbox = document.createElement('input');
-
chkbox.type='checkbox';
-
chkbox.setAttribute('name','chkPortfolio');
-
chkbox.setAttribute('id',"chkPortfolio_" + (j+1));
-
chkbox.setAttribute('value',portfolios.childNodes[j].firstChild.data);
-
if( portfolios.childNodes[j].attributes[1].text=="True") {
-
chkBox.onclick= function(evt) { refCell.set
-
}
-
else {
-
chkbox.checked=false;
-
}
-
chkbox.id = "chkPortfolio_" + (j+1);
-
chkbox.li_id = "trPortfolio_" + (j+1);
-
var name = document.createTextNode(portfolios.childNodes[j].firstChild.data);
-
listItem.appendChild(chkbox);
-
listItem.appendChild(name);
-
list.appendChild(listItem);
-
}
You had quite a few syntax problems but I ironed them out. This will work cross-browser: -
<html>
-
<head>
-
<script>
-
function blah(){
-
var j=0;
-
var chkbox = document.createElement('input');
-
chkbox.type='checkbox';
-
chkbox.setAttribute('name','chkPortfolio');
-
chkbox.setAttribute('id',"chkPortfolio_" + (j+1));
-
chkbox.setAttribute('value',"blah");
-
if( "True"=="True") {
-
chkbox.onclick= function() {alert('hi')};
-
}
-
else {
-
chkbox.checked=false;
-
}
-
chkbox.id = "chkPortfolio_" + (j+1);
-
chkbox.li_id = "trPortfolio_" + (j+1);
-
//var name = document.createTextNode(portfolios.childNodes[j].firstChild.data);
-
document.getElementById('body').appendChild(chkbox);
-
//listItem.appendChild(name);
-
//list.appendChild(listItem);
-
}
-
</script>
-
</head>
-
<body id="body" onload="blah()">
-
fdsfsdafasdfdsfsdasda
-
</body>
-
</html>
-
You had quite a few syntax problems but I ironed them out. This will work cross-browser: -
<html>
-
<head>
-
<script>
-
function blah(){
-
var j=0;
-
var chkbox = document.createElement('input');
-
chkbox.type='checkbox';
-
chkbox.setAttribute('name','chkPortfolio');
-
chkbox.setAttribute('id',"chkPortfolio_" + (j+1));
-
chkbox.setAttribute('value',"blah");
-
if( "True"=="True") {
-
chkbox.onclick= function() {alert('hi')};
-
}
-
else {
-
chkbox.checked=false;
-
}
-
chkbox.id = "chkPortfolio_" + (j+1);
-
chkbox.li_id = "trPortfolio_" + (j+1);
-
//var name = document.createTextNode(portfolios.childNodes[j].firstChild.data);
-
document.getElementById('body').appendChild(chkbox);
-
//listItem.appendChild(name);
-
//list.appendChild(listItem);
-
}
-
</script>
-
</head>
-
<body id="body" onload="blah()">
-
fdsfsdafasdfdsfsdasda
-
</body>
-
</html>
-
sorry i actually copied the wrong thing, but this helps. only problem is when... - if( "True"=="True") {
-
chkbox.onclick= function() {alert('hi')};
-
chkbox.checked=true;
-
}
i want to check the checkbox, but that doesn't seem to work. suggestions
sorry i actually copied the wrong thing, but this helps. only problem is when... - if( "True"=="True") {
-
chkbox.onclick= function() {alert('hi')};
-
chkbox.checked=true;
-
}
i want to check the checkbox, but that doesn't seem to work. suggestions
Why are you checking if "True" equals "True"? That will always return true so the code is redundant. It also means that the checkbox will never be unchecked.
should work as long as chkbox is a valid reference to a checkbox.
Why are you checking if "True" equals "True"? That will always return true so the code is redundant. It also means that the checkbox will never be unchecked.
should work as long as chkbox is a valid reference to a checkbox.
That was my bad. I hard coded that condition because he was referencing some data that wasn't in his code snippet (and I couldn't debug). I'm sure when he uses the changes he'll put it back to the way it originally was.
Why are you checking if "True" equals "True"? That will always return true so the code is redundant. It also means that the checkbox will never be unchecked.
should work as long as chkbox is a valid reference to a checkbox.
I can see the issue too. It works fine in FFox but IE doesn't show the check. I'm working on why. If anyone knows, do tell.
I can see the issue too. It works fine in FFox but IE doesn't show the check. I'm working on why. If anyone knows, do tell.
Most likely, the reason is that the checkbox must be contained within a form. So it should be appended to the body, rather it should be child to a form tag/element.
Most likely, the reason is that the checkbox must be contained within a form. So it should be appended to the body, rather it should be child to a form tag/element.
well basically i have a div called 'portfolio_box' within my form, where i append all the checkboxes i create. so i don't understand why it doesn't work in IE(6.0.2900) or FF(2.0.0.1) for me.
Then, in that case, post the entire code, or give a url to the page containing your code.
Most likely, the reason is that the checkbox must be contained within a form. So it should be appended to the body, rather it should be child to a form tag/element.
Mistake: the second sentence should be, So it should not be appended to the body, rather it should be a child element to a form/tag element.
I would've edited the original post, but it's already been quoted upon (noticed it too late).
Mistake: the second sentence should be, So it should not be appended to the body, rather it should be a child element to a form/tag element.
I would've edited the original post, but it's already been quoted upon (noticed it too late).
This is all within an aspx web page, but there is a whole bunch of other stuff going on, so i made a quick sample for a simple page. The checkboxes are selected in FF , but not IE6...any ideas? I can't get either to be checked when I essentially have this in my aspx page. Thanks for the help. - <html>
-
<header>
-
<script language="javascript">
-
function loadPort() {
-
-
var portObj = document.getElementById('portfolio_box');
-
var list = document.createElement('ul');
-
list.setAttribute('id','chk_list');
-
portObj.appendChild(list);
-
for(j=0; j<10; j++)
-
{ var listItem = document.createElement('li');
-
listItem.setAttribute('id',"trPortfolio_" + (j+1));
-
var chkbox = document.createElement('input');
-
chkbox.setAttribute('type','checkbox');
-
chkbox.setAttribute('name',"nuts");
-
chkbox.setAttribute('id',"chkPortfolio_" + (j+1));
-
chkbox.setAttribute('value',"nuts");
-
if("True"=="True") {
-
/* Nothing seems to work */
- chkbox.checked=1;
-
chkbox.checked=true;
-
chkbox.setAttribute('selected',true);
-
chkbox.setAttribute('selected','true');
-
}
-
else {
-
chkbox.checked=false;
-
}
-
chkbox.onclick= function() {
-
alert("nuts");
-
}
-
chkbox.id = "chkPortfolio_" + (j+1);
-
var name = document.createTextNode("test" + (j+1));
-
listItem.appendChild(chkbox);
-
listItem.appendChild(name);
-
list.appendChild(listItem);
-
}
-
-
portObj.appendChild(list);
-
}
-
</script>
-
-
</header>
-
-
-
<body>
-
-
-
<form id="Form1" method="post" >
-
<div id="message"></div>
-
<div class="item_list">
-
<div class="title">Portfolios <input id="checkIt" onclick="checkAll(this.checked,'chkPortfolio',60);" type="checkbox" checked></div>
-
<div id="portfolio_box"></div>
-
</div>
-
<input type="button" onclick="loadPort();" value="click me">
-
</form>
-
-
</body>
Ok, I figured it out.
IE, in its wisdom, stupidly ignores your checked setting until and unless you have appended the checkbox to something. If it's still free-standing, it just completely ignores it and sets it to (or keeps it) unchecked!
There are two ways around the problem. One is to set the checked property after you've appended the checkbox to the list-item. The second option is to use the defaultChecked property instead (thankfully, at least, IE recognises that!)
I got this info. from this site.
Of all the research I did, I could find just the hack but none explained as to why it wouldnt work with IE. Thanks to Acoder for detailed explanation.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: starace |
last post by:
I have designed a form that has 5 different list boxes where the
selections within each are used as criteria in building a dynamic
query. Some boxes are set for multiple selections but these list...
|
by: Leo J. Hart IV |
last post by:
OK, here's another question for the experts:
I am building a multi-step (3 steps actually) form using a panel for
each step and hiding/displaying the appropriate panel/panels depending
on which...
|
by: Irfan Akram |
last post by:
Hi Mr.Steve,
First of all many thanks for your kind response. The thing is that I am
trying to control the user's action of deselecting a checkbox, once he has
selected it. Also the checkbox has...
|
by: Colin |
last post by:
Hello,
I can manage quite well in ASP but would like some
advice in the best way to achieve dynamic layout
in ASP.NET and still keep the page and code
separate.
Let's say I already have a...
|
by: assgar |
last post by:
Hi
Developemnt on win2003 server. Final server will be linux
Apache,Mysql and PHP is being used.
I use 2 scripts(form and process).
The form displays multiple dynamic rows with chechboxs,...
|
by: New2ASP |
last post by:
Thanks everyone in advance for your help. I am fairly new to web development but an experienced window-based developer.
Here's the structure of my Gridview
Column 1 : Checkbox with SelectAll...
|
by: uremog |
last post by:
I have a set of of check boxes. onClick, the checkboxes call check_radio and recup_checkbox. the referenced radios function as group selectors. check_radio just unchecks the radios if someone...
|
by: =?Utf-8?B?SWRlcm9ja3M=?= |
last post by:
Hi All,
I created a dynamic checkbox in ASP .Net inside a Button1_Click event method
(outside the page_load event) and performed the event handling method for the
CheckedChanged event and I...
|
by: iderocks |
last post by:
Hi All,
I created a dynamic checkbox in ASP .Net inside a Button1_Click event method (outside the page_load event) and performed the event handling method for the CheckedChanged event and when I...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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: 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,...
|
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...
|
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...
| |