View Full Version : jQuery get value of the dynamically created checkboxes that are checked checkboxes (Help)

09-21-2010, 04:06 PM

I've been working on a project that requires me to parse an xml document and create a checkbox next to the identifier that I am getting from the xml document, but now I need to be able to get the value of the checked checkboxes.
Here is the code I am using to parse the document, so the name of the checkbox isn't the same as the identifier. If anyone could help me figure out how to dynamically create the checkboxes so that the name/id is the same as the identifier.

var html1 = "<div class=\"entry\"><form name= \"codes\" >";

$(d).find('dictionaryEntry').each(function() {
var $dictionaryEntry = $(this);

// console.log($dictionaryEntry.find('identifier').text());

var identifier = $dictionaryEntry.find('identifier').text();
var html = "<input type=\"checkbox\" name=\"code\">" + identifier + "</input>";



var html2 = "</form></div><br />";

And here is the code I am using to go and find what boxes are checked and append the value to a div.

$('#Code input[type="checkbox"]:checked').each(function() {
console.log("This is what u got: " + $(this).innerHTML);
var text = $(this).text();

It would be greatly appreciated if someone could explain how to either get the identifier using html or innerhtml or some other method, or to show me how to create an id for each checkbox that is equal to the identifier it got from the xml document and then how to append that value to my parentElem div.

09-21-2010, 05:48 PM
I wouldn't create your checkboxes like that.

var html = '<input type="checkbox" id="code_'+ identifier +'" name="code" value="'+ identifier +'"/><label for="code_'+ identifier +'">'+ identifier +'</label>';

you should then be able to get the values with

$('#Code input[type="checkbox"]:checked').each(function() {

09-21-2010, 06:15 PM
It works!!!! Thank you!!!!!!!!!!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum