php - How to get the textarea ID using jQuery -
ive got textarea area on each table row unique id . how retrieve unique id javascript?
php:
$query = $db->query("select * bs_events eventdate = '".$date."'"); while($row = $query->fetch_array(mysqli_assoc)){ echo '<textarea id=\"att_name_" . $row['id'] . "\" style=\"width:300px\"></textarea>";' }
php output:
<textarea id="att_name_1" style="width:300px"> <textarea id="att_name_2" style="width:300px"> <textarea id="att_name_3" style="width:300px">
jquery:
$(document).ready(function(){ $("#book_event").submit(function(){ id = event.target.id.replace('att_name_',''); $.post("scripts/book_event.php", { att_name: $("att_name_"+id).val(), }, function(data){ if(data.success) { $("#err").text(data.message).fadein("slow"); } }, "json"); }); });
it looks me you're naming textareas correlate database entries, trying make updates , pass values back. assuming textareas in form you're submitting, can use:
$('#myform').submit(function(e){ // find each of text areas $(this).find('textarea[id^=att_name]').each(function(i,e){ // // here-in, e represents 1 of textareas // // submit update $.post('scripts/book_event.php',{ att_name: $(e).val() },function(data){ if (!data.success) $("#err").text(data.message).fadein("slow"); },'json'); }); e.preventdefault(); });
ideally though, if you're looking use ajax push updates/changes server, may in .serialize()
, push forms back. then, on server-side you'll standard $_post['att_name_1']
values can use actual updating. e.g.
// .serialize() example $('#myform').submit(function(e){ $.post('scripts/book_event.php',$(this).serialize(),function(data){ if (!data.success) $("#err").text(data.message).fadein("slow"); }); e.preventdefault(); });
Comments
Post a Comment