Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > createElement and checkboxs

Reply
Thread Tools

createElement and checkboxs

 
 
Iain Downie
Guest
Posts: n/a
 
      08-11-2004
Dear List,

I have a snippet of code below that creates a new input element for a
checkbox and sets some attributes.

var observationCheckbox = document.createElement('input');
observationCheckbox.setAttribute('type', 'checkbox');
observationCheckbox.setAttribute('id', 'observation.' + runningCount +
'.species');
observationCheckbox.setAttribute('name', 'observation.' + runningCount +
'.species');
observationCheckbox.setAttribute('value', 's' + speciesCode);

Question: Is it possible to set this checkbox to be 'checked' when it is
created? I'm not sure if this constitutes an attribute or not.

Thanks
Iain
www.bto.org/birdweb




 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      08-11-2004


Iain Downie wrote:

> I have a snippet of code below that creates a new input element for a
> checkbox and sets some attributes.


> Question: Is it possible to set this checkbox to be 'checked' when it is
> created?


Use
var observationCheckbox = document.createElement('input');
observationCheckbox.type = 'checkbox';
observationCheckbox.checked = observationCheckbox.defaultChecked = true;

--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
 
 
 
Iain Downie
Guest
Posts: n/a
 
      08-11-2004

"Martin Honnen" <> wrote in message
news:411a3f5c$...
>
> Use
> observationCheckbox.checked = observationCheckbox.defaultChecked =

true;
>


Martin......

brilliant.

Thanks
Iain


 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Repeater and Checkboxs Kevin Humphreys ASP .Net Web Controls 2 11-28-2006 09:06 AM
elegant coding style - checkboxs JJ ASP .Net 2 07-31-2006 02:36 PM
Checkboxs Oli Javascript 7 10-18-2004 12:49 PM
calculating in table made by createElement and appendChild kie Javascript 25 10-07-2003 11:38 AM
Checkboxs inside a listbox MS News ASP .Net 5 07-27-2003 07:14 PM



Advertisments