I have a script like this:
$(function() {
$(".btn_bookmark").click(function() {
var name = $("input.???").val();
base_url = '<?php echo base_url() ?>';
$.ajax({
url: base_url+"bookmark/bookmark_item/"+name,
success: function() {
// do something on success
}
});
return false;
});
});
And my form is inside a PHP loop like so:
foreach($page->result() as $row){
echo '<form name="" method="post" action="">';
echo '<input type="hidden" name="'$row->name'" id="'.$row->id.'" size="30" value="'.$row->val.'" />';
echo '<input type="submit" name="submit" class="btn_bookmark" id="submit_btn" value="Bookmark" />';
echo '</form>';
}
The problem is each of the forms hidden input name, id, and value are different/dynamic from a MySQL database. So how would I select the correct value for the input?
Rather than grabbing
var name = $("input.???").val();You can grab the hidden input like this:
This gets the parent of the element triggering the event (in this case the form) then grabs the hidden input child of this parent.