Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question get value of the dynamically created checkboxes that are checked checkboxes (Help)

    Hello,

    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.



    Code:
    var html1 = "<div class=\"entry\"><form name= \"codes\" >";
        $('#Code').append($(html1));
    			
    		$(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>"; 
    
    			$('#Code').append($(html));
    
    		});
    
        var html2 = "</form></div><br />";
        $('#Code').append($(html2));		
    	});

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



    Code:
    $('#Code input[type="checkbox"]:checked').each(function() { 
          console.log("This is what u got: " + $(this).innerHTML);   
                var text = $(this).text();     
          $('#parentElem').append($(this).val(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.

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    I wouldn't create your checkboxes like that.

    Code:
    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:
    $('#Code input[type="checkbox"]:checked').each(function() { 
        $('#parentElem').append($(this).val());
    });

  • Users who have thanked Spudhead for this post:

    kpowell (09-21-2010)

  • #3
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It works!!!! Thank you!!!!!!!!!!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •