www.webdeveloper.com
Results 1 to 3 of 3

Thread: Add to checkboxs

Hybrid View

  1. #1
    Join Date
    Mar 2013
    Posts
    61

    Add to checkboxs

    I'm new to using Jquery and I need some help adding a checkbox to an already defined feildset. My code below, followed by the HTML.

    Code:
    function showAddress() 
    {
    	var sAddress = document.getElementById("textinput1").value;
    	
    	geocoder.geocode( { 'address': sAddress}, function(results, status) {
    		
    		if (status == google.maps.GeocoderStatus.OK) 
    		{
    			document.getElementById("locBoxes").innerHTML+= "<input type='checkbox' name='checkbox3' id='checkbox3_" + bookmarksArray.length+2 + "' class='custom' value='' /><label for='checkbox3_" + bookmarksArray.length+2 + "'>" + sAddress + "</label>";
    			
    		}
    		else
    		{
    			alert("Address not found.");
    		}
    		 
    	});
    }
    HTML Code:
    <fieldset data-role="controlgroup" id="locBoxes">
                <input type="checkbox" name="checkbox2" id="checkbox2_0" class="custom" value="" />
                <label for="checkbox2_0">Blossom House School</label>
                <input type="checkbox" name="checkbox2" id="checkbox2_1" class="custom" value="" />
                <label for="checkbox2_1">Cannon Hill Common</label>
                <input type="checkbox" name="checkbox2" id="checkbox2_2" class="custom" value="" />
                <label for="checkbox2_2">1 Firstway, Greater London, SW20 0JD</label>
              </fieldset>
    A checkbox is created, but it's not a member of the field set. The only way I can explain it is with this pic.

    http://i39.tinypic.com/2h72yxh.png

  2. #2
    Join Date
    Jul 2013
    Posts
    11
    is it added to the field set and just the css doesn't work for it or is it really outside the field set?

    but where i can help:
    if you use jQuery you can replace "document.getElementById('id')" with "$('id')"

    so your code would look like this:
    (i have replaced innerHTML+= with append())

    Code:
    function showAddress() 
    {
    	var sAddress = $("textinput1").val();
    	
    	geocoder.geocode( { 'address': sAddress}, function(results, status) {
    		
    		if (status == google.maps.GeocoderStatus.OK) 
    		{
    			$("locBoxes").append("
                                  <input type='checkbox' name='checkbox3' id='checkbox3_" + bookmarksArray.length+2 + "'
                                  class='custom' value='' /><label for='checkbox3_" + bookmarksArray.length+2 + "'>" + 
                                  sAddress + "</label>
                            )";
    		}
    		else
    		{
    			alert("Address not found.");
    		}
    		 
    	});
    }

  3. #3
    Join Date
    Mar 2013
    Posts
    61
    Quote Originally Posted by schaet View Post
    is it added to the field set and just the css doesn't work for it or is it really outside the field set?

    but where i can help:
    if you use jQuery you can replace "document.getElementById('id')" with "$('id')"

    so your code would look like this:
    (i have replaced innerHTML+= with append())

    Code:
    function showAddress() 
    {
    	var sAddress = $("textinput1").val();
    	
    	geocoder.geocode( { 'address': sAddress}, function(results, status) {
    		
    		if (status == google.maps.GeocoderStatus.OK) 
    		{
    			$("locBoxes").append("
                                  <input type='checkbox' name='checkbox3' id='checkbox3_" + bookmarksArray.length+2 + "'
                                  class='custom' value='' /><label for='checkbox3_" + bookmarksArray.length+2 + "'>" + 
                                  sAddress + "</label>
                            )";
    		}
    		else
    		{
    			alert("Address not found.");
    		}
    		 
    	});
    }

    Thanks for the info. For some reason when I try to change my function to fit yours my else alert is activated. Weird I know. It half works. The append part does, but t's still the seem problem. It doesn't seem to apply the css I think.

    EDIT: Also for whatever reason it stops the rest of my check boxes from working. Any that follow do, but the three before stop/.
    Last edited by KarneeKarnay; 07-10-2013 at 09:04 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles