How to create Check Box and Select Tag

R

Raghuram Banda

Hi there,

I'm new programmer in JavaScript. Can any one help in creating a
checkbox (by default selected) from JavaScript and creating Drop down
box (<select> ... </select>) from Javascript.

Thanks In Advance
 
L

Lasse Reichstein Nielsen

Raghuram Banda said:
I'm new programmer in JavaScript. Can any one help in creating a
checkbox (by default selected) from JavaScript

var cb = document.createElement("input"); // create input node
cb.type = "checkbox"; // set type
cb.name = "checkboxName"; // set name if necessary
cb.checked = cb.defaultChecked = true; // make it checked now and by default

formRef.appendChild(cb); // add it to some form
and creating Drop down
box (<select> ... </select>) from Javascript.

var se = document.createElement("select");
cb.name = "selectName";
se.options[0] = new Option("selection 1","value 1");
se.options[1] = new Option("selection 2","value 2");
se.options[2] = new Option("selection 3","value 3");
se.options[3] = new Option("selection 4","value 4");

formRef.appendChild(se);

Hope this helps.
/L
 

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,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top