php - how to select specfic hidden element from a form in a loop in javascript? -
so basically, loop outputs 4 times html below different values in $show_id. everyform returns $show_id value of first form instead of value of form when function called. how fix ?
my javascript
<script type="text/javascript" > function addscore() { var show_id = $('#show_id').val(); var user_id = $('#user_id').val(); var score = $('input[name=tvshowrating]:checked').val(); if(score=='') { alert('pleaseenter score'); } else { $("#flash").show(); $("#flash").html('<img src="ajax-loader.gif" />loading score...'); $.ajax({ type: "post", url: "showscoreajax.php", data:{ "show_id" : show_id, "user_id" : user_id, "score" : score //we passing name value in url }, cache: false, success: function(data){ $("#flash").html('added'); } }); } return false; }; </script> myhtml
<div id="flash"></div> <form id="form3b"> <div class="your-score"> <div class="">your score</div> <input class="hover-star" type="radio" name="tvshowrating" value="1" title="1"/> <input class="hover-star" type="radio" name="tvshowrating" value="2" title="2"/> <input class="hover-star" type="radio" name="tvshowrating" value="3" title="3"/> <input class="hover-star" type="radio" name="tvshowrating" value="4" title="4"/> <input class="hover-star" type="radio" name="tvshowrating" value="5" title="5"/> <input class="hover-star" type="radio" name="tvshowrating" value="6" title="6"/> <input class="hover-star" type="radio" name="tvshowrating" value="7" title="7"/> <input class="hover-star" type="radio" name="tvshowrating" value="8" title="8"/> <input class="hover-star" type="radio" name="tvshowrating" value="9" title="9"/> <input class="hover-star" type="radio" name="tvshowrating" value="10" title="10"/> <input type="hidden" id="show_id" value="<?php echo $row[0]; ?>" /> <input type="hidden" id="user_id" value="<?php echo $user_id ?>" /> <span id="hover-test" style="margin:0 0 0 20px;"></span> <input id="submitscore" type="submit" value="submit scores!" onclick="addscore()" /> </div> </form> </div> </div>
this because cannot have duplicate id's unlike duplicate class need different ids each form. this
<input type="hidden" id="show_id-form3b" value="<?php echo $row[0]; ?>" /> then possible unique value of each different forms. thing this
function addscore(formid) { var show_id = $('#show_id-'+formid).val(); var user_id = $('#user_id-'+formid).val(); //add code }
Comments
Post a Comment