Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / April 2005



Tip: Looking for answers? Try searching our database.

ck my checkbox input

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mike - 29 Apr 2005 01:16 GMT
I am dynamically creating an input that is a checkbox like:

myINPUT = document.createElement("INPUT");
myINPUT.type = "checkbox";
myINPUT.id = myINPUT.name = "myck_box";
myINPUT.value = "Y";
myINPUT.checked = true;
myINPUT.disabled = true;
mike - 29 Apr 2005 01:20 GMT
I forgot to mention that it is not getting checked ....
mscir - 29 Apr 2005 02:31 GMT
> I forgot to mention that it is not getting checked ....

This works on my IE 6, Netscape 7.2, Firefox 1.0.3, Mozilla 1.7.3 :

  var myDiv = document.getElementById('somediv');
  var myINPUT = document.createElement("INPUT");
  myINPUT.type = "checkbox";
  myINPUT.id = "myck_box";
  myINPUT.name = "myck_box";
  myINPUT.value = "Y";
  myINPUT.disabled = true;
  myDiv.appendChild(myINPUT);
  myINPUT.checked = true;
mike - 29 Apr 2005 02:36 GMT
I see .... I have to check it after I create it, i.e. I can't create it
in the "checked" condition.

Thanks, let me try that
Fred Oz - 29 Apr 2005 03:51 GMT
> I see .... I have to check it after I create it, i.e. I can't create it
> in the "checked" condition.

 No, for IE you have to check it after you *add it to the document*,
 Firefox is quite happy for you to check it anytime after it is
 created.

 Until the checkbox is added to the document (either by appending it
 to an element that is part of the document, or adding its parent
 element to the document), IE will not check it.

 In either case you must create it first before you can do anything
 with it - I suspect that will be true of all browsers.

> Thanks, let me try that

 Ok.

Signature

Fred

Dietmar Meier - 29 Apr 2005 12:40 GMT
> I see .... I have to check it after I create it, i.e. I can't create
> it in the "checked" condition.

You can. When the checkbox is added to the document (or when the
document is (re)loaded or the form reset), its "defaultChecked"
property determines its initial checked status.

myINPUT = document.createElement("INPUT");
myINPUT.type = "checkbox";
myINPUT.id = myINPUT.name = "myck_box";
myINPUT.value = "Y";
myINPUT.defaultChecked = true;
myINPUT.disabled = true;

ciao, dhgm
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.