mercredi 27 mai 2015

get the value in checkbox per select in jquery using codeigniter

Hi i have this checkbox select and my button when saved the data i use .click function. My problem is i want to get the value of the checkbox based on what youve clicked say for example i have this checkbox data

ap-apartment
hs-house
lf-loft
as-asdsad

when i clicked the ap-apartmen,hs-house,lf-loft and clicked submit i want to get their valued based on what ive selected. My checkbox data is dynamic based on what the user added. Here's my checkbox view Property Type:

                                <?php foreach($propertyType as $propType): ?>
                                    <input type="checkbox" name="propertyType[]" id="propertyType" value="<?php echo $propType->id;?>" > <?php echo $propType->itemkey."-".$propType->itemvalue;?><br>
                                <?php endforeach; ?>

 <button type="button" id="propertyButton" class="btn btn-primary">Save</button>

my jquery code

     $("#propertyButton").click(function(){

                $('input[name^="propertyType"]').each(function() {
                        alert($(this).val());
                });
});

the alert will get all the value in a checkbox even if only i check only one data. can someone help me figured this thing out? any help is muchly appreciated.TIA




Aucun commentaire:

Enregistrer un commentaire