Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
C#
function checkData(PrjList)
{

   var handler = document.getElementById("LoadCheckbox");
   var val=PrjList;
   console.log(val);
 var checkbox = document.createElement('input');
checkbox.type = "checkbox";
checkbox.name = "name";
checkbox.value = val;
checkbox.id = val;

var label = document.createElement('label')
label.appendChild(document.createTextNode(val));

handler.appendChild(checkbox);
handler.appendChild(label);
}


Above is a function to create a checkbox.'Prjlist' is the values to be given in the checkbox,that is passed from other function.i can display the values but the checkbox sign doesnot appear.
Can anybody identify what is the problem here???Please help...
Posted
Updated 21-May-14 21:10pm
v2
Comments
Peter Leow 22-May-14 3:13am    
What do you mean "checkbox sign doenot appear"? you code looks fine.
p@y@l 22-May-14 3:36am    
The small square box doesnot appear..
Ajith K Gatty 22-May-14 3:19am    
did u mean by " check box sign doesn't appear " that u cant see the small void square box??? but only label is visible.
p@y@l 22-May-14 3:36am    
yes.I mean the same..
Ajith K Gatty 23-May-14 1:36am    
u have a variable handler. is that the div object where you want to place the check box??

Hi,

C#
label.appendChild(checkbox);   // add the box to the element
label.appendChild(document.createTextNode(val));// add the description to the element

// add the label element to your div
document.getElementById('div').appendChild(label);


use this and check the result once.

Good Luck
 
Share this answer
 
The code I posted was correct,because of the css style applied in it the checkbox was not visible..Thanks for the help every1
 
Share this answer
 
using below code checkbox is created

JavaScript
var checkbox = document.createElement('checkbox') 




After creating checkbox you need to append to your page to display checkbox

JavaScript
document.getElementById(parentElementId).appendChild(checkbox);



Hope it will work for you

Enjoy..11
 
Share this answer
 
v2
Comments
p@y@l 11-Jun-14 7:10am    
its working fine now thank you.
please use checked attribute instead of value

JavaScript
function checkData(PrjList)
{
checkbox.checked = val;
}
 
Share this answer
 
Comments
p@y@l 22-May-14 3:42am    
but this wont show the check box sign..I need the square box to be shown in screen. :(
Sunasara Imdadhusen 11-Jun-14 6:34am    
Hey Payal,
what is LoadCheckbox id it div or what? Can you please provide your HTML code as well
p@y@l 11-Jun-14 7:09am    
Yes it is a DIV element- <div id="LoadCheckbox"></div>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900