Powered By Blogger

Thursday, January 9, 2014

change the field value in any field using ajax add that changed value in dynamically

HTML

<select id="select_catagory" name="plm-Qnty">
               <option value="0"></option>
          <option value="199">1/4kg - INR 199</option>
               <option value="399 ">1/2kg - INR 399 </option>
               <option value="699">1 kg - INR 699</option>

               </select>

JQUERY

<script type="text/javascript">
$(document).ready(function()
{
$("#select_catagory").change(function()
{
var id=$(this).val();
var val1 = $("#select_catagory1").val();
var val2 = $("#select_catagory2").val();
var val3 = $("#select_catagory3").val();
var val4 = $("#select_catagory4").val();
var val5 = $("#select_catagory5").val();
var val6 = $("#select_catagory6").val();
var sum = (parseInt(val1)) + (parseInt(val2)) + (parseInt(val3)) + (parseInt(val4)) + (parseInt(val5)) + (parseInt(val6));
//alert(sum);
var dataString = 'id='+ id +'&sum=' + sum;
$.ajax
({
type: "POST",
url: "add.php",
data: dataString,
cache: false,
success: function(html)
{
$("#select_value").html(html);
}
});

});


});
</script>



Add.php

<?php 

if($_POST['id'])
@$id = $_POST['id'];
@$sum = $_POST['sum'];
$tot = $id + $sum;
echo '<input type="text" value="'.$tot.'"/>';

}

?>

No comments:

Post a Comment