Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-30-2002, 01:34 PM   PM User | #1
Zvona
Regular Coder

 
Join Date: May 2002
Location: Helsinki, Finland
Posts: 231
Thanks: 0
Thanked 1 Time in 1 Post
Zvona is an unknown quantity at this point
Input (checkbox) object

Edit : Blue parts are added after jkd's suggestion.

Following code does not work on IE. Moz handles it nicely.

Can anybody say, how to set for IE whether checbox is checked? I've tried also setAttribute() and to set checked property to "checked", but none of these works on IE .
Code:
<!-- Example Written by Zvona -->
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
	<head>
		<title>Creating a checked checkbox</title>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1;" />
		<script type="text/javascript">
		window.onload	= function()
		{
			var oForm	= document.createElement("form");
			var oCheckB	= document.createElement("input");
			var oButton	= document.createElement("input");

			oCheckB.setAttribute("type","checkbox");
			oCheckB.checked	= true;

			oButton.setAttribute("type","button");
			oButton.onclick	= function()
			{
				document.forms[0].elements[0].checked = !oCheckB.checked;
			}

			oForm.appendChild(oCheckB);
			oForm.appendChild(oButton);

			document.body.appendChild(oForm);
		}
		</script>
	</head>

	<body>
	</body>
</html>
__________________
Zvona
First Aid for
Web Design

Last edited by Zvona; 07-31-2002 at 10:08 AM..
Zvona is offline   Reply With Quote
Old 07-30-2002, 06:55 PM   PM User | #2
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
Well, I see two possibilities:

#1. IE is stupid (well, that's the cause of this anyway ), and when it sees the <?xml?> processing instruction in a .html document, it throws itself into quirks mode. This may somehow affect how properties are done on dynamically created elements, though I couldn't say for sure.

#2. Have you tried setting checked = true when the node is live in the page? i.e. after you have appended the form and checkbox to the body, try setting the checkbox checked property. I don't see any reason why that shouldn't work in IE, though it would be slightly inefficient to modify a "live" object.
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 07-31-2002, 10:22 AM   PM User | #3
Zvona
Regular Coder

 
Join Date: May 2002
Location: Helsinki, Finland
Posts: 231
Thanks: 0
Thanked 1 Time in 1 Post
Zvona is an unknown quantity at this point
Quote:
Originally posted by jkd
#2. Have you tried setting checked = true when the node is live in the page? i.e. after you have appended the form and checkbox to the body, try setting the checkbox checked property. I don't see any reason why that shouldn't work in IE, though it would be slightly inefficient to modify a "live" object.
Yup, that was the problem. I fixed the code above to demonstrate checking/unchecking a box is possible with IE after the node is appended.

However, I've still got a problem : I've created a constructor, which applies data from db,
var myCheckBox = new Checkbox(<% =rsSet("bOnline") %>);

where bOnline is a boolean whether current record is online or not. How can I tell to function Checkbox to re-apply boolean value for object after it's appended into document?

C'est impossible?
__________________
Zvona
First Aid for
Web Design
Zvona is offline   Reply With Quote
Old 07-31-2002, 06:18 PM   PM User | #4
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
When you appendChild(), it returns a reference to the live node:

var form = document.createElement('form');
var radio = document.createElement('input');
radio.setAttribute('type', 'radio');

form.appendChild(radio);

form = document.body.appendChild(form);
radio = form.lastChild;
radio.checked = true;
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:48 PM.


Advertisement
Log in to turn off these ads.