Dynamic Check boxs in jsp and Java script

Hi ,
I would like to create Dynamic Check Boxes using Java scritp.I got id and name from DataBase.So using those values in Need to build check Boxes in JSP Page.
I use Below Code but it returns only [object] not checkboxes.
Java script :

 var checkbox = document.createElement('input');
 	 checkbox.type = "checkbox";
	 checkbox.name = id;
	 checkbox.id = id;
         checkbox.value = name;
						 document.getElementById("attri_types").innerHTML= checkbox;

<div id=attri_types></div>

Please help to fix this issue.Thanks in advance.

I don’t use the .innerHTML property, but I thought that was supposed to be a string value?

Since you already have a DOM node, you can just add it to the parent’s collection:


Thank you so much.it works fine.

function getCheckBoxes() {
    var attributeVal;
	for (i=0; i<document.attributeRuleMaintainForm.attrtype.length; i++){
        if (document.attributeRuleMaintainForm.attrtype[i].checked==true)
        	attributeVal = document.attributeRuleMaintainForm.attrtype[i].value
	    // Create the AJAX object
		var xmlHttp = CreateHttpRequest();
		// Create the action that will be taken when the
		// reponse has been received.
		xmlHttp.onreadystatechange = function() {
	 	if(xmlHttp.readyState == 4 && xmlHttp.responseXML) {
	 		var optionElements1 = xmlHttp.responseXML.getElementsByTagName('option');
				if (optionElements1.length > 0) {
					document.getElementById("attri_types").innerHTML= " ";
					for(var i = 0; i < optionElements1.length; i++) {
						 var id = optionElements1[i].getElementsByTagName('id')[0].firstChild.nodeValue;
						 var name = optionElements1[i].getElementsByTagName('name')[0].firstChild.nodeValue;
						 var value = value+"<br>"+ id ;

						 if(id > 0) {
							 var checkbox =  document.createElement('input');
							 checkbox.type = "checkbox";
							 checkbox.name = "attribute";
							 checkbox.id = "attribute";
							 checkbox.value = name;
							 //checkbox.onclick = testit;

							 var text = document.createTextNode( name );
							var breake = document.createElement("<br>");
	            document.getElementById( 'attri_types' ).appendChild( checkbox );
	                        document.getElementById( 'attri_types' ).appendChild( text );
	                        document.getElementById( 'attri_types' ).appendChild( breake );
						 } else {
						    document.getElementById("attri_types").innerHTML= "Records not found";
		var url = "./xxxxxxxxx.dd?action=getCheckboxInfo&attrtype="+attributeVal;

		// Send the request

Any help?

What does it insert when you use innerHTML on the containing element?

Your code looks pretty legitimate (although make sure you have quotes around the id attribute of the element if you haven’t already)