php - How to display all checkboxes values in a div using ajax -


i have multiple checkboxes displayed mysql table. i'm trying pass checked values <div> using ajax. currently, code passes 1 checked value <div>. want display checked values in <div>.

what have far:

 <?php $sql="select  * options cat_id='".$id."' , opg_id='".$group."'";  $result = mysql_query($sql);  while($row = mysql_fetch_array($result)){ ?>  <input type="checkbox" name="<?php echo $row['op_id']; ?>" onclick="showprice(this.name)" value="<?php echo $row['price']; ?>"/>  <!-- display prices mysql table in checkbox. pass `id` ajax name attribute. --> <?php } ?> 

ajax

<script> function showprice(name) {  $.ajax({         url: 'ajax_price.php',         type: 'get',         data: {option : name},         success: function(data) {            document.getelementbyid('c').innerhtml =data;         }     }); } </script> 

ajax_price.php

<?php include ("../supplier/db/db.php"); $id = $_request['option'];   <?php $sql="select  * options op_id='".$id."'";  $result = mysql_query($sql); while($row = mysql_fetch_array($result)){   ?>  <div class="oder">          <div class="odercol2"><?php echo $row['opt']; ?></div>          <div class="odercol3"><?php echo $row['price']; ?></div>      </div> <?php } ?> 

this display 1 checked value in <div>. want display checked values in <div>.

checkboxes

checkboxes

results display in div (div id "c")

results display in div

just change ajax function concat innerhtml of div, this:

<script> function showprice(name) {  $.ajax({         url: 'ajax_price.php',         type: 'get',         data: {option : name},         success: function(data) {            document.getelementbyid('c').innerhtml += data;         }     }); } </script> 

notice line document.getelementbyid('c').innerhtml += data; hope works. thanks


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -