createElement and checkboxs

I

Iain Downie

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
 
M

Martin Honnen

Iain said:
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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top