I am just new in this using javascript and I am having a hard time in appending a value from a checkbox to a table cell with a inputbox inside. When I check one of the checkbox(fee_type) the table is populated by all the fee types from the data base and plus the the amount table must be populated in the amount and penalty table(please see attached image of the actual view form)... please help me with this problem.
Thank you very much in advance.
The Actual View Form
--Form View--
<div class="form-group">
<label>Grade Level</label>
<select id="class_id" name="class_id" class="form-control" >
<option value=""><?php echo $this->lang->line('select'); ?></option>
<?php foreach ($classlist as $class) { ?>
<option value="<?php echo $class['id'] ?>"
<?php if (set_value('class_id') == $class['id']) {
echo "selected =selected";
}
?>><?php echo $class['class'] ?></option>
<?php
$count++;
}
?>
</select>
<span class="text-danger"><?php echo form_error('class_id'); ?></span>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Fee Group Name</label>
<select autofocus="" id="fee_groups_id" name="fee_groups_id" class="form-control" >
<option value=""><?php echo $this->lang->line('select'); ?></option>
</select><span class="text-danger"><?php echo form_error('fee_groups_id'); ?></span>
</div>
<div class="form-group">
<label>amount</label>
<input id="amount" name="amount" placeholder="" type="text" class="form-control" value="<?php echo set_value('amount'); ?>" />
<span class="text-danger"><?php echo form_error('amount'); ?></span>
</div>
<div class="form-group">
<label>Penalty</label>
<input id="penalty" name="penalty" placeholder="" type="text" class="form-control"/>
<span class="text-danger"><?php echo form_error('penalty'); ?></span>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="exampleInputEmail1">Fee type</label>
<?php foreach ($feetypeList as $feetype) { ?>
<div class="checkbox" >
<label style="display: inline-block; max-height: 25px; list-style: none; float: left; padding-top: 5px; width: 130px; margin-right: 40px;">
<input id="chkAdd" type="checkbox" name="feetype_id" value="<?php echo $feetype['id'] ?>" <?php echo set_checkbox('feetype', $feetype['id']); ?> ><?php echo $feetype['type'] ?>
</label>
</div>
<?php } ?>
<span class="text-danger"><?php echo form_error('feetype_id'); ?></span>
</div>
--Javascript--
<script type="text/javascript">
$(function () {
$(document).on("click", "#chkAdd", function () {
var lenght_div = $('#TextBoxContainer .app').length;
var div = GetDynamicTextBox(lenght_div);
$("#TextBoxContainer").append(div);
});
$(document).on("click", "#btnGet", function () {
var values = "";
$("input[name=DynamicTextBox]").each(function () {
values += $(this).val() + "\n";
});
});
});
function GetDynamicTextBox(value) {
var row = "";
$('#chkAdd:checked').each(function(){
row += '<tr class="tableGroup">';
<?php foreach ($feetypeList as $feetype) { ?>
row += '<td class="mailbox-name"><input class="form-control" name="feetype_id" value="<?php echo set_value('feetype_id', $feetype['type']); ?>"/></td>';
row += '<td class="mailbox-name"><input class="form-control" name="startDate" value="<?php echo set_value('startDate', $feetype['start_date']); ?>"/></td>';
row += '<td class="mailbox-name"><input class="form-control" name="endDate" value="<?php echo set_value('startDate', $feetype['end_date']); ?>"/></td>';
row += '<td class="mailbox-name"><input id="amountCell" name="amountCell" placeholder="" type="text" class="form-control"/></td>';
row += '<td class="mailbox-name"><input id="penaltyCell" name="penaltyCell" placeholder="" type="text" class="form-control"/></td>';
row += '</tr>';
<?php
$count++;
}
?>
});
row = row.substring();
$(".tableGroup").val(row);
return row;
}
</script>
<script type="text/javascript">
$(document).ready(function () {
$(".feemaster_form").submit(function (e)
{
$("#TextBoxContainer").html("");
$.ajax(
{
url: formURL,
type: "POST",
data: postData,
dataType: 'json',
success: function (data, textStatus, jqXHR)
{
if (data.st === 1) {
$.each(data.msg, function (key, value) {
$('.' + key + "_error").html(value);
});
} else {
var response = data.msg;
if (response && response.length > 0) {
for (i = 0; i < response.length; ++i) {
var feetype_id = response[i].feetype_id;
var row_id = response[i].id;
appendRow(feetype_id, row_id);
}
} else {
appendRow(0, 0, 0);
}
$('#chkAdd');
}
},
error: function (jqXHR, textStatus, errorThrown)
{
}
});
e.preventDefault();
});
});
function appendRow() {
var value = $('#TextBoxContainer .app').length;
var row = "";
row += '<td class="mailbox-name"><input class="form-control" name="feetype_id" value="<?php echo set_value('feetype_id', $feetype['type']); ?>"/></td>';
row += '<td class="mailbox-name"><input class="form-control" name="startDate" value="<?php echo set_value('startDate', $feetype['start_date']); ?>"/></td>';
row += '<td class="mailbox-name"><input class="form-control" name="endDate" value="<?php echo set_value('startDate', $feetype['end_date']); ?>"/></td>';
row += '<td class="mailbox-name"><input id="amountCell" name="amountCell" placeholder="" type="text" class="form-control"/></td>';
row += '<td class="mailbox-name"><input id="penaltyCell" name="penaltyCell" placeholder="" type="text" class="form-control"/></td>';
$count++;
row += '</tr>';
$("#TextBoxContainer").append(row);
}
</script>
Related
Ok so as you can see in the code snip bellow I am creating choices (inputs) in number (1) in number (2) I display the choice's name and in number (3) I display the unit price.
(1) is a number from 1 to n, I want to take the input number from each (1) and multiply it with the unit price (3) (example x=(1)*(3)) and then sum all of these results and display them in another textbox.
I have tried several things but I couldn't make it happen.
I could really use some guidance here.
Any more information I will be happy to provide.
<?php
$sum = $choice['qty'] * $choice['timi'];
foreach($choice3 as $choice3){
?>
//(1)
<input type="number" class="colorqty" name="color[<?php echo $i; ?>][unit]" step="<?php echo $step; ?>" value="0" min="0" class="color_qty_1" onchange="updateTotal();">
//(2)
<input type="text" value="<?php echo $choice3['price_name']; ?>" name="color[<?php echo $i; ?>][price_name]" readonly="readonly" class="color_qty_2">
//(3)
<input type="text" value="<?php echo $choice3['price']."€"; ?>" name="xrwmas" readonly="readonly" class="color_qty_2" id="tests"> <br />
<?php $i++; } ?>
for example from the loop above we get
I want to multiply in this example 5 * 68, 0 * 74, etc and then sum the results and display it in the sum box.
#Jerson is close but I it gets really messed up this is a bit of an edit on his code but still can't figure it out.
<input type="number" style="width:40px" class="colorqty" id="input_value" step="1" value="0" min="0" onchange="updateSum();">
<input type="text" value="58" readonly="readonly" class="color_qty_3" id="price">
<br>
<input type="number" style="width:40px" class="colorqty" id="input_value" step="1" value="0" min="0" onchange="updateSum();">
<input type="text" value="33" readonly="readonly" class="color_qty_3" id="price">
<br>
<input type="number" style="width:40px" class="colorqty" id="input_value" step="1" value="0" min="0" onchange="updateSum();">
<input type="text" value="54" readonly="readonly" class="color_qty_3" id="price">
<br>
<input type="number" style="width:40px" class="colorqty" id="input_value" step="1" value="0" min="0" onchange="updateSum();">
<input type="text" value="55" readonly="readonly" class="color_qty_3" id="price">
<br>
<br><br>
<label for="sinolo" class="color_qty_2" style="margin-left:45px"> Σύνολο €</label>
<input type="number" class="color_qty_2" style="background-color:white;color:black;width: 90px; border-color:black;border-radius:5px; border-width:1px; text-align:center;" value="<?php echo number_format((float)$sum, 2, '.', ''); ?>" id="a3" readonly="readonly">
and the js
function updateSum(value,id) {
var elements = document.getElementsByTagName('input')
var input_val = 0;
var price_val = 0;
var some_test = 0;
var test1 = 0;
for(let i = 0 ; i < elements.length; i++) {
if(elements[i].getAttribute('id') == 'price') {
price_val = parseInt(elements[i].value)
}
if(elements[i].getAttribute('id') == 'input_value') {
input_val = parseInt(elements[i].value)
}
test1 = price_val*input_val;
some_test += test1;
document.getElementById('a3').value = some_test
}
}
This works fine for me
<?php Route::add('/route', function() {
$array = [
[
'price_name' => 'Xiaomi Poco X3',
'price' => 2000
],
[
'price_name' => 'Xiaomi Poco F1 plus',
'price' => 1500
],
[
'price_name' => 'Xiaomi Poco F1',
'price' => 1000
]
];
foreach($array as $key => $value) {
?>
<div id="form">
<input type="number" id="input_value" class="colorqty" name="color[<?php echo $key; ?>][unit]" value="0" min="0" class="color_qty_1" onkeyup="updateTotal();">
<input type="text" value="<?php echo $value['price_name']; ?>" name="color[<?php echo $key; ?>][price_name]" readonly="readonly" class="color_qty_2">
<input type="text" data-id="<?php echo $key; ?>" value="<?php echo $value['price']."€"; ?>" id="price" name="xrwmas" readonly="readonly" class="color_qty_2" id="tests"> <br />
</div>
<?php
}
echo '<p>SUM <span id="sum">0</span></p>';
?>
<script>
function updateTotal(value,id) {
var elements = document.getElementsByTagName('input')
var input_val = 0;
var price_val = 0;
for(let i = 0 ; i < elements.length; i++) {
if(elements[i].getAttribute('id') == 'price') {
price_val += parseInt(elements[i].value.replace('€',''))
}
if(elements[i].getAttribute('id') == 'input_value') {
input_val += parseInt(elements[i].value)
}
}
document.getElementById('sum').innerHTML = !Number.isNaN(price_val * input_val) ? price_val * input_val : 0
}
</script>
<?php
});
?>
Will you need only javascript todo that
So I did figure it out #Jerson helped out a lot.
So for the code in the beginning we add unique id in all items we need. In this example price and input so here is the example
<?php
foreach($choice3 as $choice3){
?>
//(1)
<input type="number" class="colorqty" name="color[<?php echo $i; ?>][unit]" step="<?php echo $step; ?>" value="0" min="0" class="color_qty_1" onchange="updateSum();" id="input_value_<?php echo $i; ?>">
//(2)
<input type="text" value="<?php echo $choice3['price_name']; ?>" name="color[<?php echo $i; ?>][price_name]" readonly="readonly" class="color_qty_2">
//(3)
<input type="text" value="<?php echo $choice3['price']."€"; ?>" name="xrwmas" readonly="readonly" class="color_qty_2" id="price_<?php echo $i; ?>">
Then we just need the JS that takes one element by class and counts its length and then well you as you can see makes it work for infinite inputs.
function updateSum(value,id) {
var elements = document.getElementsByClassName('colorqty').length;
var input_val = 0;
var price_val = 0;
var multipl = 0;
var output = 0;
var i = 0;
while(i < elements ) {
price_val = document.getElementById('price_'+[i]).value;
input_val = document.getElementById('input_value_'+[i]).value;
if(input_val != null){
multipl = price_val*input_val;
output += multipl ;
document.getElementById('a3').value = !Number.isNaN(output) ? output : 0
}
i ++;
}
}
and here is the working example in jsfiddle
I'm trying to get class id for a dynamic table rows, the first row is working perfectly when it's selected, but the other rows are being fetched from java-scripts and are not working.
i.e. I can't get the class ids from the rows that is fetching from the java-script table row.
//this is jquery function am using....
$('#course_code').click(function(){
var course_id = $('#course_code').val();
if(course_id != '')
{
$.ajax({
url:"<?php echo base_url('Undergraduate_pg/fetch_course_code'); ?>",
method:"POST",
data:{course_id:course_id},
success:function(data){
$('#course_cod').val(data);
}
})
}
})
//this is the javascript table rows that is loading dynamically using click button..
function addrows(){
var row = ($('.detail tr').length-0)+1;
var tr = '<tr>' +
'<th>'+row+'</th>' +
'<td><select class="form-control course_code" id="course_code" name="course_code[]" required><option value="" selected="selected">Select Course Code</option><?php if (isset($pos)) { ?><?php foreach ($pos as $row) { ?>
echo "<option> <?php echo $row->course_code; ?></option>";<?php } } ?></select></td>' +
'<td><select class="form-control course_title" id="Title" name="course_title[]" required><option value="" selected="selected">Select Course Title</option><?php if (isset($pos)) { ?><?php foreach ($pos as $row) { ?>
echo "<option> <?php echo $row->course_title; ?></option>";<?php } } ?></select></td>' +
'<td><input type="number" class="form-control unit_elect" id="course_units" name="course_unit[]" value="" required></td>' +
'<td><select class="form-control course_status" id="course_status" name="course_status[]" required><option value="" selected="selected">Select Course Status</option><?php if (isset($pos)) { ?><?php foreach ($pos as $row) { ?>
echo "<option> <?php echo $row->course_status; ?></option>";<?php } } ?></select></td>' +
'<td colspan="3"><a class="btn btn-danger remove" >X</a></td>'+
'</tr>';
$('.detail').append(tr);
}
</script>
//i expect both static row and the dynamic row should be working once selected..
<!--this is the html code.. note, only this is working....-->
<tbody class="detail">
<td>1</td>
<td><select class="form-control course_code" id="course_code" name="course_code" required>
<option value="">--Select Course Code--</option>
<?php if (isset($pos)) { ?>
<?php foreach ($pos as $row) { ?>
echo "<option value="<?php echo $row->course_id; ?>"> <?php echo $row->course_code; ?></option>";
<?php } } ?>
</select>
<input type="text" class="form-control course_cod" id="course_cod" name="course_code[]" required>
</td>
I expect both static row and the dynamic row should be working once selected.
This is my database table. I'm currently displaying option1-10 as text but I want to display it as an input type for each option depending if its answer_type column is radiobutton or checkbox. It also shouldn't display when the value of option1-10 is null. Also how do i group it into one like for example if it's a radiobutton, i should only be able to choose one?
Here's my code of displaying the text
ajax
<html>
<head>
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","hay.php?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
</html>
<form>
<select name="users" onchange="showUser(this.value)">
<option>-None Selected-</option>
<?php
$con = mysqli_connect('localhost','root','','imetrics') or die ("Cannot connect");
$query=mysqli_query($con, "SELECT * FROM question");
while($row=mysqli_fetch_array($query)) {
?>
<option value="<?php echo $row["question_id"]; ?>"><?php echo $row["questiontitle"]; ?></option>
<?php
}
?>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here...</b></div>
php code
<?php
$con = mysqli_connect('localhost','root','','imetrics') or die ("Cannot connect to database");
if(!$con){
echo ('Could not connect: ' . mysqli_error($con));
}
$id= isset($_GET["q"])?$_GET["q"]:"";
$query = mysqli_query($con, "SELECT * FROM question WHERE question_id = '".$id."'");
while($row = mysqli_fetch_array($query)) {
echo $row['Option_1'] . "<br>";
echo $row['Option_2'] . "<br>";
echo $row['Option_3'] . "<br>";
echo $row['Option_4'] . "<br>";
echo $row['Option_5'] . "<br>";
echo $row['Option_6'] . "<br>";
echo $row['Option_7'] . "<br>";
echo $row['Option_8'] . "<br>";
echo $row['Option_9'] . "<br>";
echo $row['Option_10'] . "<br>";
}
?>
What's the right condition for my problem?
You just have to put a bit more work into it. Also, using intval for SQL injection attack prevention. I am using a function to prevent duplicate copy-pasted code. I'm also escaping the data from the database as it might contain "<" or "&".
<?php
$con = mysqli_connect('localhost','root','','imetrics') or die ("Cannot connect to database");
if(!$con){
echo ('Could not connect: ' . mysqli_error($con));
}
$id= isset($_GET["q"])?intval($_GET["q"]):"";
$query = mysqli_query($con, "SELECT * FROM question WHERE question_id = '".$id."'");
function displayOption($i, $value, $answer_type) {
if($value == null) {
return;
}
if($answer_type == "radiobutton") {
echo '<input type="radio" name="rinput" value="'.htmlspecialchars($value, ENT_QUOTES).'">'.htmlspecialchars($value).'<br>';
} else if($answer_type == "checkbox") {
echo '<input type="checkbox" name="cinput['.$i.']" value="'.htmlspecialchars($value, ENT_QUOTES).'">'.htmlspecialchars($value).'<br>';
}
}
while($row = mysqli_fetch_assoc($query)) {
for($i = 1; $i<=10; ++$i) {
displayOption($i, $row["Option_$i"], $row['answer_type']);
}
}
?>
Try this,
if($row['answer_type']=='radiobutton'){
echo '<input type="radio" name="" value="" /> '.$row['Option_1']."<br />";
echo '<input type="radio" name="" value="" /> '.$row['Option_2']."<br />";
echo '<input type="radio" name="" value="" /> '.$row['Option_3']."<br />";
echo '<input type="radio" name="" value="" /> '.$row['Option_4']."<br />";
echo '<input type="radio" name="" value="" /> '.$row['Option_5']."<br />";
echo '<input type="radio" name="" value="" /> '.$row['Option_6']."<br />";
echo '<input type="radio" name="" value="" /> '.$row['Option_7']."<br />";
echo '<input type="radio" name="" value="" /> '.$row['Option_8']."<br />";
echo '<input type="radio" name="" value="" /> '.$row['Option_9']."<br />";
echo '<input type="radio" name="" value="" /> '.$row['Option_10']."<br />";
}
else if($row['answer_type']=='checkbox'){
echo '<input type="checkbox" name="" value="" /> '.$row['Option_1']."<br />";
echo '<input type="checkbox" name="" value="" /> '.$row['Option_2']."<br />";
echo '<input type="checkbox" name="" value="" /> '.$row['Option_3']."<br />";
echo '<input type="checkbox" name="" value="" /> '.$row['Option_4']."<br />";
echo '<input type="checkbox" name="" value="" /> '.$row['Option_5']."<br />";
echo '<input type="checkbox" name="" value="" /> '.$row['Option_6']."<br />";
echo '<input type="checkbox" name="" value="" /> '.$row['Option_7']."<br />";
echo '<input type="checkbox" name="" value="" /> '.$row['Option_8']."<br />";
echo '<input type="checkbox" name="" value="" /> '.$row['Option_9']."<br />";
echo '<input type="checkbox" name="" value="" /> '.$row['Option_10']."<br />";
}
else{
// nothing.
}
Try this:
while($row = mysqli_fetch_array($query)) {
if($row['answer_type']=='radiobutton'){
echo '<input type="radio" name="options" value='".$row['Option_1']."' > echo $row['Option_1'] . "<br>";
.
.
.//all other options
}else{
echo '<input type="checkbox" name="options" value='".$row['Option_1'] ."'>'$row['Option_1'].<br>
. "<br>";
.
.
.//all other options
}
}
Hi guys i have an issue for displaying all data where a column with name header_id having same data. but when it displayed, his result
just one row. actually of data with header_id='100002' having 4 rows.Thanks.
Model:
function getdtHeaderid($header_id = FALSE) {
if ($header_id === FALSE)
{
$query = $this->db1->get('tbltransactiondtl');
return $query->result_array();
}
$query = $this->db1->get_where('tbltransactiondtl', array('header_id' => $header_id));
return $query->row_array();
}
Controller:
function getdtHeaderid() {
$header_id = $this->input->post('header_id');
$data=$this->M_selltransaction->getdtHeaderid($header_id);
echo json_encode($data);
}
View:
<div class="col-md-6">
<label for="header_id" class="col-md-4 control-label" style="text-align:left">Transaction No</label>
<label class="col-md-1 control-label">:</label>
<div class="col-md-6">
<div class="input-group input-group-unstyled">
<input type="text" class="header_id form-control" placeholder="Search" id="header_id" name="header_id"/>
<span class="input-group-addon"><i class="fa fa-search "></i></span>
</div>
</div>
</div>
<table>
<td><input type="text" width="10" class="detail_id form-control"
id="detail_id" name="detail_id[]" value="<?php $a =
set_value('detail_id[0]'); echo $a;?>" required ></td>
<td><input
type="text" width="10" class="item_code form-control" id="item_code"
name="item_code[]" value="<?php $a = set_value('item_code[0]'); echo
$a;?>" required ></td>
<td><input type="text" class="item_name
form-control" id="item_name" name="item_name[]" value=""
readonly></td>
</table>
<script type="text/javascript">
function getdHeaderid(header_id){
var header_id = header_id.val();
$.ajax({
type : "post",
data : {header_id:header_id},
url : "<?php echo base_url();?>index.php/transaction/selltransaction/getdtHeaderid",
dataType:"json",
cache :false,
success: function(data){
console.log(data);
$(".detail_id").val(data.detail_id);
$(".item_code").val(data.item_code);
$(".item_name").val(data.item_name);
}
});
}
$(document).ready(function() {
$('.header_id').on('keyup change', function() {
getdHeaderid($(this));
});
});
function getdtHeaderid($header_id = FALSE) {
if ($header_id === FALSE)
{
$query = $this->db1->get('tbltransactiondtl');
return $query->result_array();
}
$query = $this->db1->get_where('tbltransactiondtl', array('header_id' => $header_id));
return $query->result_array();
}
Here is Your Correct model function you were using row_array() instead of result_array() thats why getting only one result
update
$(".detail_id").val(data.detail_id);
$(".item_code").val(data.item_code);
$(".item_name").val(data.item_name);
to
$(".detail_id").val(data[0].detail_id);
$(".item_code").val(data[0].item_code);
$(".item_name").val(data[0].item_name);
Below is my HTML code. I can only get value returned by ajax request in that id="sss" field.
My Problems are listed below with images:-
<form id="dynamic2" action="<?= site_url('product/save') ?>" method="post">
<table class="table">
<tbody id="itemlist2" class="detailss">
<tr>
<td>
<select id="select-product" class="form-control" data-cell="B1" name="product_name[]">
<option value="">
</option>
<?php
foreach ($product as $key ):
?>
<option value="<?php echo $key['id'] ?>">
<?php echo $key['product_name'] ?>
</option>
<?php endforeach; ?>
</select>
</td>
<td>
<input type="text" id="sss" data-cell="C1" name="price[]" class="form-control" value="">
</td>
<td>
<input type="text" data-cell="D1" name="quantity[]" class="form-control">
</td>
<td>
<input type="text" data-cell="E1" name="discount[]" class="form-control">
</td>
<td>
<input type="text" data-cell="F1" name="total[]"
disabled="true" data-formula="(D1*C1)-(D1*C1*E1/100)"
class="form-control">
</td>
</tr>
</tbody>
<input type="submit" value="Submit" class="btn btn-primary">
</table>
</form>
I am not getting value returned by ajax request in dynamically created input fields.
Here is my dynamically created input field jS code.
<script type="text/javascript">
$(function() {
$form = $('#dynamic2').calx();
$('.addrowss').click(function() {
$itemlist = $('#itemlist2');
$counter = 5;
var i = ++$counter;
var tr = '<tr>' +
'<td><select id="select-product" class="form-control" data-cell="B' + i + '" name="product_name[]"><option value=""></option><?php
foreach ($product as $key ):
?><option value="<?php echo $key['product_name'] ?>"><?php echo $key['product_name'] ?></option><?php endforeach; ?></select></td>'+
'<td><input id="sss" type="text" data-cell="C' + i + '" name="price[]" class="form-control" value=""></td>' +
'<td><input type="text" data-cell="D' + i + '" name="quantity[]" class="form-control"></td>' +
'<td><input type="text" data-cell="E' + i + '" name="discount[]" class="form-control"></td>' +
'<td><input type="text" class="form-control" data-cell="F' + i + '" name="total[]" data-formula="(D' + i + '*C' + i + ')-(D' + i + '*C' + i + '*E' + i + '/100)"></td>' +
'<td>Remove</td>' +
'</tr>';
$('.detailss').append(tr);
$form.calx('update');
$form.calx('getCell', 'G1').setFormula('SUM(F1:F' + i + ')');
});
$('body').delegate('.remove', 'click', function() {
var tr = $(this).parent().parent();
var c = confirm("Do you want to remove this ?");
if (c) {
tr.remove();
}
});
});
</script>
Ajax Code
<script type="text/javascript">
$(document).ready(function() {
$("#select-product").change(function() {
var id = $(this).val();
// alert(id);
$.ajax({
type: "GET",
url: "<?php echo site_url('/product/view_data'); ?>",
data: {
"id": id
},
cache: false,
success: function(data) {
var tmp = data.split(",");
$('#sss').val(tmp[6]);
}
});
});
});
</script>
Product.php Controller
public function view_data()
{
if(isset($_GET['id'])){
$this->load->model('Product_model');
$id = $_GET['id'];
$param = $this->Product_model->get_ajax_value($id);
foreach($param as $a)
echo $a.",";
exit;
}
}
I am not exactly sure why it isn't returning all the correct data. But here might be a step to help you debug you problem.
Add a console.log(data); To see what is being returned from the ajax call. Use the console of your browser to see this.
Change your code to:
<script type="text/javascript">
$(document).ready(function () {
$("#select-product").change(function () {
var id = $(this).val();
// alert(id);
$.ajax({
type: "GET",
url: "<?php echo site_url('/product/view_data'); ?>",
data: {"id":id},
cache: false,
success: function(data){
console.log(data); //this will show what is returned.
var tmp = data.split(",");
$('#sss').val(tmp[6]);
}
});
});
});
I understand this isn't the complete answer to your code. But it might put you on the right track to seeing what the server is returning to your client side code.