php - how to check a value is being properly selected (or not) by javascript? -
i'm trying add value radio button form db javascript doesn't return errors , it's not working. think selector might not working how check ? what's wrong function ?
js
<script type="text/javascript" > function addscore() { $("#submitscore").click(function() { 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").fadein(400).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(html){ $("#flash").html('added'); } }); }return false; }); }; </script> html
<form id="form3b"> <div class="your-score"> <div class="">your score</div> <div id="flash"></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> </div> </div></div> <input id="submitscore" type="submit" value="submit scores!" onclick="addscore()" /> <u>test results</u>:<br/><br/> <div class="test smaller"> <span style="color:#ff0000">results displayed here</span> </div> </form>
there no need use $("#submitscore").click(function() in addsote() method since called on click on button
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").fadein(400).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(html){ $("#flash").html('added'); } }); } return false; };
Comments
Post a Comment