sql - AJAX - looped variables, only first result being passed -
i loop data sql query , put form. 3 variables being retrieved sql each data set: betid
, bethome
, betaway
.
now i'd alter data within form , pass through ajax.
problem: first data set being altered, others remain untouched.
any idea wrong javascript code?
<script type="text/javascript"> $(document).ready(function(){ $("#betting").click(function(){ var val1 = $("#betid").val(); var val2 = $("#bethome").val(); var val3 = $("#betaway").val(); $.ajax({ type: "post", url: "betting-ajax.php", data: { betid: val1, bethome: val2, betaway: val3 }, success: function(html){ $("#hide").hide(); $("#new").html(html); } }); return false; }); }); </script>
php structure:
<form id="betting"> sql query starting here { <select id="bethome"><option value="1">1</option></select> <select id="betaway"><option value="1">1</option></select> <input type="hidden" name="betid" id="betid" value="<?php echo $betid ?>" <button type="submit" name="submit">save</button> <?php } ?> </form>
as said form (query inside form) , above explained javascript code, first data set gets altered, followed data set not changing.
can try ?
<script type="text/javascript"> $(document).ready(function(){ var val1 = $("#betid").val(); var val2 = $("#bethome").val(); var val3 = $("#betaway").val(); $("#bethome").on("change", function(){ val1 = $(this).val(); }); $("#betaway").on("change", function(){ val1 = $(this).val(); }) $("#betting").click(function(){ $.ajax({ type: "post", url: "betting-ajax.php", data: { betid: val1, bethome: val2, betaway: val3 }, success: function(html){ $("#hide").hide(); $("#new").html(html); } }); return false; }); }); </script>
the reason need new value of changed drop down.
Comments
Post a Comment