I'm working on button groups which are retrieving by PHP echo from database and need to post values by Ajax. This is shortly about creating product main groups, sub groups and products.
This is the code for creating and listing buttons:
echo '
<a class="altgrup_al">
<input type="hidden" name="data_id" id="data_id" value="1">
<input type="hidden" name="san_RECno" id="san_RECno" value="'.$san_RECno.'">
<button type="button" class="btn btn-mini btn-primary" style="margin-
left:5px; margin-bottom:5px; height:80px; width:80px; white-
space:normal;">'.$san_isim.'</button></a>';
And this is the ajax code for posting:
<script>
$(document).ready(function(){
$(".altgrup_al").click(function(e){
e.preventDefault();
var deger = document.getElementById('data_id').value;
var sth_fatura_no = document.getElementById('sth_fatura_no').value;
var san_RECno = document.getElementById('san_RECno').value;
$.ajax({
type: "POST",
url: "altgrup_al.php",
data: {deger:deger, sth_fatura_no:sth_fatura_no, san_RECno:san_RECno},
success: function(result){
$("#alt_tablo").html(result);
}
});
});
});
</script>
i tried also data-id attribute but in any style of ajax posting,
var san_RECno = document.getElementById('san_RECno').value;
this value = 1.
But when i list buttons and show the value of san_RECno
, each button shows its own id number.
I'm not good on JavaScript enough so i need help why always posting same (1) id number.
Thanks.