php - Jquery submit radio button without reload and -
so because experience jquery 0 have no idea how run mysql script when form submitted without reloading page? in short form radio button submit --> form sended --> query without reload
my script:
<form id="myform" method="get"> <div class="row"> <div class="span4 info1"> <section class="widget"> <img src="../bootstrap/img/thumb/0.jpg" width="auto" height="auto"> <?php if ($selectedbg == '0') { echo '<h2>current one</h2>'; } ?> <input type="radio" name="options[]" value="0" onclick="document.getelementbyid('myform').submit();"/> choose background </section> </div> </div> <?php $checked = $_get['options']; ($i = 0; $i < count($checked); $i++) { $sql = 'update blog_users set background = '.$checked[$i].' username=?'; $bg = $db->prepare($sql); $bg->execute(array($session->username)); } ?> </form>
so question how submit form without reloading page + running query?
you need create separate page accepts form data, , use jquery's ajax functions asynchronously submit data.
here pseudocode show how accomplish this:
$('form').on('click', 'input:radio', function() { $.get('new_page_url' + $(this).serialize(), function(data) { // function success function. // page should return kind of information let function // know submission successful on server side well. // can manipulate dom let user know submission // successful. }); });
Comments
Post a Comment