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 9584
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: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |