Ajax not displaying content - javascript

So i have part where AJAX updates cart on click. Every AJAX call on my website is working fine except this one where call is processed but it just clears part of the page that should've been updated. So on both buttons click after <tbody id="korpin"> everything is cleared until next div.
Cart.php
<tbody id="korpin">
<?php
$conn = new mysqli("localhost", "root", "", "pc") or die("Unable to connect");
foreach($_SESSION['korpica'] as $id => $korpa):
$sql = $conn->prepare("SELECT a.sifra,a.slika,a.imeProizvoda,a.brend,b.cijena,b.cijena2 FROM proizvodi a inner join stanje b on a.sifra = b.sifra WHERE a.sifra = '".$korpa."'");
if($sql->execute()){
$sql->bind_result($sifra,$slika,$imeProizvoda,$brend,$cijena,$cijena2);
$sql->store_result();
while($sql->fetch()){
?>
<tr>
<td class="text-center"><img width="70px" src="image/proizvodi/<?php echo $slika; ?>.jpg" alt="<?php echo $imeProizvoda; ?>" title="<?php echo $imeProizvoda; ?>" class="img-thumbnail" /></td>
<td class="text-left"><?php echo $imeProizvoda; ?><br />
</td>
<td class="text-left"><?php echo $brend; ?></td>
<td class="text-left" width="200px"><div class="input-group btn-block quantity">
<span class="input-group-btn">
<button type="button" data-toggle="tooltip" title="+1" class="btn btn-primary" onclick="dodaj(`<?php echo $sifra; ?>`); cart.add(`<?php echo(str_replace('"', '\\`', $imeProizvoda)); ?>`); refresh(`<?php echo $sifra; ?>`);"><i class="fa fa-clone"></i></button>
<button type="button" data-toggle="tooltip" title="Ukloni" class="btn btn-danger" onclick="ukloni(`<?php echo $sifra; ?>`); sd.remove(`<?php echo(str_replace('"', '\\`', $imeProizvoda)); ?>`); refresh(`<?php echo $sifra; ?>`);"><i class="fa fa-times-circle"></i></button>
</span></div></td>
<?php if ($cijena2 > 0): ?>
<td class="text-right">€<?php echo bcdiv($cijena2,1,2); ?></td>
<td class="text-right">€<?php echo bcdiv($cijena2,1,2); ?></td>
<?php else :?>
<td class="text-right">€<?php echo bcdiv($cijena,1,2); ?></td>
<td class="text-right">€<?php echo bcdiv($cijena,1,2); ?></td>
<span class="price-old"></span>
<?php endif ?>
</tr>
<?php
}$sql->free_result();
} endforeach;
$conn->close();
?>
</tbody>
korpinUpd.js
function refresh(sifra) {
$.ajax({
url: 'cartUpdate.php',
success : function(data) {
$('#korpin').html(data);
}
});
}
and finally cartUpdate.php
<?php
session_start();
$output ='';
$cena; $conn = new mysqli("localhost", "root", "", "pc") or die("Unable to connect");
foreach($_SESSION['korpica'] as $id => $korpa){
$sql = $conn->prepare("SELECT a.sifra,a.slika,a.imeProizvoda,a.brend,b.cijena,b.cijena2 FROM proizvodi a inner join stanje b on a.sifra = b.sifra WHERE a.sifra = '".$korpa."'");
if($sql->execute()){
$sql->bind_result($sifra,$slika,$imeProizvoda,$brend,$cijena,$cijena2);
$sql->store_result();
while($sql->fetch()){
$output.= '<tr>';
$output.='<td class="text-center"><img width="70px" src="image/proizvodi/'.$slika.'.jpg" alt="'.$imeProizvoda.'" title="'.$imeProizvoda.'" class="img-thumbnail" /></td>
<td class="text-left">'.$imeProizvoda.'<br />
</td>
<td class="text-left">'.$brend.'</td>
<td class="text-left" width="200px"><div class="input-group btn-block quantity">
<span class="input-group-btn">
<button type="button" data-toggle="tooltip" title="+1" class="btn btn-primary" onclick="dodaj(`'.$sifra.'`); cart.add(`'.(str_replace('"', '\\`', $imeProizvoda)).'`); refresh(`'.$sifra.'`);"><i class="fa fa-clone"></i></button>
<button type="button" data-toggle="tooltip" title="Ukloni" class="btn btn-danger" onclick="ukloni(`'.$sifra.'`); sd.remove(`'.(str_replace('"', '\\`', $imeProizvoda)).'`); refresh(`'.$sifra.'`);"><i class="fa fa-times-circle"></i></button>
</span></div></td>';
if ($cijena2 > 0){
$cena = $cijena2;
}else{
$cena = $cijena;
}
$output .= '<td class="text-right">€'.$cena.'</td>
<td class="text-right">€'.$cena.'</td>';
$output .= '</tr>';
}
}}
$conn->close();
echo $output;
?>

Try echo json_decode($output); , your AJAX call might not recognize what you are sending.

Related

Get the unique total scores of students

I have a form on my school web application where teachers are able to add scores for students and at the end of each row, the total, which is the sum of input values is automatically calculated per student.
The problem is that it output the total of all the students instead of the total of individual students on all the rows even ones with no scores added.
How do I get the unique total value for each row?
Below is my code
<?php if($class_id >= 1 && $class_id <= 4 && $student['is_secmid'] == 1){?>
<form method="post" action="<?php echo site_url('admin/examgroup/entrymarks') ?>" id="assign_form1111">
<input type="hidden" id="max_mark" value="<?php echo $subject_detail->max_marks; ?>">
<?php
if (isset($resultlist) && !empty($resultlist)) {
?>
<div class="row">
<div class="col-md-12">
<input type="hidden" name="exam_group_class_batch_exam_subject_id" value="<?php echo $exam_group_class_batch_exam_subject_id; ?>">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>C.A 1 (10.0)</th>
<th>C.A 2 (10.0)</th>
</tr>
</thead>
<tbody>
<?php if (empty($resultlist)) {
?>
<tr>
<td colspan="7" class="text-danger text-center"><?php echo $this->lang->line('no_record_found'); ?></td>
</tr>
<?php
} else {
foreach ($resultlist as $student) {
?>
<tr class="std_adm_<?php echo $student['admission_no']; ?>">
<input type="hidden" name="prev_id[<?php echo $student['exam_group_class_batch_exam_students_id'] ?>]" value="<?php echo $student['exam_group_exam_result_id'] ?>">
<input type="hidden" name="exam_group_student_id[]" value="<?php echo $student['exam_group_class_batch_exam_students_id'] ?>">
<td><?php echo $student['admission_no']; ?></td>
<td style="white-space: nowrap;"><?php echo $student['lastname'] . " " . $student['firstname']; ?></td>
<td> <input type="number" class="marksssss2 form-control" min="0" max="10" name="exam_group_student_ca1_<?php echo $student['exam_group_class_batch_exam_students_id']; ?>" value="<?php echo $student['exam_group_exam_result_get_ca1']; ?>" step="any"></td>
<td> <input type="number" class="marksssss3 form-control" min="0" max="10" name="exam_group_student_ca2_<?php echo $student['exam_group_class_batch_exam_students_id']; ?>" value="<?php echo $student['exam_group_exam_result_get_ca2']; ?>" step="any"></td>
<td> <output class="result"></output></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
<?php if ($this->rbac->hasPrivilege('exam_marks', 'can_edit')) { ?>
<button type="submit" class="allot-fees btn btn-primary btn-sm pull-right" id="load" data-loading-text="<i class='fa fa-spinner fa-spin '></i> Please Wait.."><?php echo $this->lang->line('save'); ?>
</button>
<?php } ?>
</div>
</div>
<?php } ?>
<script>
const $inputs = $('input[type="number"]')
$inputs.change(function() {
var total = 0;
var parent = $(this).closest('.row');
parent.find('input[type="number"]').each(function() {
if ($(this).val() != '') {
total += parseInt($(this).val());
}
});
parent.find('.result').html(total);
});
</script>
you missed class row on <tr> and you are trying to find it on closest div from javascript, and you are getting this (<div class="row">), it have all the (<input type="number").
you forget to add class to TR. Add class row on <tr> so you can get all (<input type="number") inside the tr.
because of not added class on TR you are facing issue that all total have same numbers.

Remove HTML Attributes and tags

Hi i need to remove HTML attributes and tags using php but strip_tag not working give any solutions. Some span attributes come along with the table values. I need to update editable table values in mysql db. Please find the attached Error Image in console log. I am working opencart ecommerce site. Its different kind of php language.
View File
<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
<div class="page-header">
<div class="container-fluid">
<div class="pull-right"><i class="fa fa-plus"></i>
<button type="submit" form="form-product" formaction="<?php echo $copy; ?>" data-toggle="tooltip" title="<?php echo $button_copy; ?>" class="btn btn-default"><i class="fa fa-copy"></i></button>
<button type="button" data-toggle="tooltip" title="<?php echo $button_delete; ?>" class="btn btn-danger" onclick="confirm('<?php echo $text_confirm; ?>') ? $('#form-product').submit() : false;"><i class="fa fa-trash-o"></i></button>
</div>
<h1><?php echo $heading_title; ?></h1>
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><?php echo $breadcrumb['text']; ?></li>
<?php } ?>
</ul>
</div>
</div>
<div class="container-fluid">
<?php if ($error_warning) { ?>
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
<?php } ?>
<?php if ($success) { ?>
<div class="alert alert-success"><i class="fa fa-check-circle"></i> <?php echo $success; ?>
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
<?php } ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-list"></i> <?php echo $text_list; ?></h3>
</div>
<div class="panel-body">
<div class="well">
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label class="control-label" for="input-name"><?php echo $entry_name; ?></label>
<input type="text" name="filter_name" value="<?php echo $filter_name; ?>" placeholder="<?php echo $entry_name; ?>" id="input-name" class="form-control" />
</div>
<div class="form-group">
<label class="control-label" for="input-model"><?php echo $entry_model; ?></label>
<input type="text" name="filter_model" value="<?php echo $filter_model; ?>" placeholder="<?php echo $entry_model; ?>" id="input-model" class="form-control" />
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label class="control-label" for="input-price"><?php echo $entry_price; ?></label>
<input type="text" name="filter_price" value="<?php echo $filter_price; ?>" placeholder="<?php echo $entry_price; ?>" id="input-price" class="form-control" />
</div>
<div class="form-group">
<label class="control-label" for="input-quantity"><?php echo $entry_quantity; ?></label>
<input type="text" name="filter_quantity" value="<?php echo $filter_quantity; ?>" placeholder="<?php echo $entry_quantity; ?>" id="input-quantity" class="form-control" />
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label class="control-label" for="input-status"><?php echo $entry_status; ?></label>
<select name="filter_status" id="input-status" class="form-control">
<option value="*"></option>
<?php if ($filter_status) { ?>
<option value="1" selected="selected"><?php echo $text_enabled; ?></option>
<?php } else { ?>
<option value="1"><?php echo $text_enabled; ?></option>
<?php } ?>
<?php if (!$filter_status && !is_null($filter_status)) { ?>
<option value="0" selected="selected"><?php echo $text_disabled; ?></option>
<?php } else { ?>
<option value="0"><?php echo $text_disabled; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label class="control-label" for="input-image"><?php echo $entry_image; ?></label>
<select name="filter_image" id="input-image" class="form-control">
<option value="*"></option>
<?php if ($filter_image) { ?>
<option value="1" selected="selected"><?php echo $text_enabled; ?></option>
<?php } else { ?>
<option value="1"><?php echo $text_enabled; ?></option>
<?php } ?>
<?php if (!$filter_image && !is_null($filter_image)) { ?>
<option value="0" selected="selected"><?php echo $text_disabled; ?></option>
<?php } else { ?>
<option value="0"><?php echo $text_disabled; ?></option>
<?php } ?>
</select>
</div>
<div class="col-sm-12">
<div class="form-group">
<label class="control-label" for="input-date"><?php echo $entry_date; ?></label>
<input type="text" name="filter_date" value="<?php echo $filter_date; ?>" placeholder="<?php echo $entry_date; ?>" id="input-date" class="form-control" />
</div>
<!--<div class="form-group">
<label class="control-label" for="input-quantity"><?php //echo $entry_quantity; ?></label>
<input type="text" name="filter_quantity" value="<?php //echo $filter_quantity; ?>" placeholder="<?php //echo $entry_quantity; ?>" id="input-quantity" class="form-control" />
</div>-->
</div>
<button type="button" id="button-filter" class="btn btn-primary pull-right"><i class="fa fa-filter"></i> <?php echo $button_filter; ?></button>
</div>
</div>
</div>
<form action="<?php echo $delete; ?>" method="post" enctype="multipart/form-data" id="form-product">
<div class="table-responsive">
<table class="table table-bordered table-hover">
<thead>
<tr>
<td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>
<td class="text-center"><?php echo $column_image; ?></td>
<td class="text-left"><?php if ($sort == 'pd.name') { ?>
<?php echo $column_name; ?>
<?php } else { ?>
<?php echo $column_name; ?>
<?php } ?></td>
<td class="text-left"><?php if ($sort == 'p.model') { ?>
<?php echo $column_model; ?>
<?php } else { ?>
<?php echo $column_model; ?>
<?php } ?></td>
<td class="text-left"><?php if ($sort == 'p.seo') { ?>
<?php echo $column_seo; ?>
<?php } else { ?>
<?php echo $column_seo; ?>
<?php } ?></td>
<td class="text-left"><?php if ($sort == 'p.date') { ?>
<?php echo $column_date; ?>
<?php } else { ?>
<?php echo $column_date; ?>
<?php } ?></td>
<td class="text-right"><?php if ($sort == 'p.price') { ?>
<?php echo $column_price; ?>
<?php } else { ?>
<?php echo $column_price; ?>
<?php } ?></td>
<td class="text-right"><?php if ($sort == 'p.quantity') { ?>
<?php echo $column_quantity; ?>
<?php } else { ?>
<?php echo $column_quantity; ?>
<?php } ?></td>
<td class="text-left"><?php if ($sort == 'p.status') { ?>
<?php echo $column_status; ?>
<?php } else { ?>
<?php echo $column_status; ?>
<?php } ?></td>
<td class="text-right"><?php echo $column_action; ?></td>
</tr>
</thead>
<tbody>
<?php if ($products) { ?>
<?php foreach ($products as $product) { ?>
<tr id = "<?php $product['product_id'];?>" >
<td class="text-center"><?php if (in_array($product['product_id'], $selected)) { ?>
<input type="checkbox" name="selected[]" value="<?php echo $product['product_id']; ?>" checked="checked" />
<?php } else { ?>
<input type="checkbox" name="selected[]" value="<?php echo $product['product_id']; ?>" />
<?php } ?></td>
<td class="text-center"><?php if ($product['image']) { ?>
<img src="<?php echo $product['image']; ?>" alt="<?php echo $product['name']; ?>" class="img-thumbnail" />
<?php } else { ?>
<span class="img-thumbnail list"><i class="fa fa-camera fa-2x"></i></span>
<?php } ?></td>
<td class="text-left"><?php echo $product['name']; ?></td>
<td class="text-left"><?php echo $product['model']; ?></td>
<td class="text-left"><?php echo $product['keyword']; ?></td>
<td class="text-left"><?php echo $product['date_available']; ?></td>
<td contenteditable="true" onblur = "update(this, 'price','<?php echo $product['product_id']; ?>')" class="text-right"><?php if ($product['special']) { ?>
<span style="text-decoration: line-through;"><?php echo $product['price']; ?></span><br/>
<div class="text-danger"><?php echo $product['special']; ?></div>
<?php } else { ?>
<?php echo $product['price']; ?>
<?php } ?></td>
<td contenteditable="true" onblur = "update(this, 'quantity','<?php echo $product['product_id']; ?>')" class="text-right"><?php if ($product['quantity'] <= 0) { ?>
<span class="label label-warning"><?php echo $product['quantity']; ?></span>
<?php } elseif ($product['quantity'] <= 5) { ?>
<span class="label label-danger"><?php echo $product['quantity']; ?></span>
<?php } else { ?>
<span class="label label-success"><?php echo $product['quantity']; ?></span>
<?php } ?></td>
<td class="text-left"><?php echo $product['status']; ?></td>
<td class="text-left"><i class="fa fa-pencil"></i>
<!--<i class="fa fa-save"></i>--></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td class="text-center" colspan="8"><?php echo $text_no_results; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</form>
<div class="row">
<div class="col-sm-6 text-left"><?php echo $pagination; ?></div>
<div class="col-sm-6 text-right"><?php echo $results; ?></div>
</div>
</div>
</div>
</div>
<script type="text/javascript"><!--
$('#button-filter').on('click', function() {
var url = 'index.php?route=catalog/product&token=<?php echo $token; ?>';
var filter_name = $('input[name=\'filter_name\']').val();
if (filter_name) {
url += '&filter_name=' + encodeURIComponent(filter_name);
}
var filter_model = $('input[name=\'filter_model\']').val();
if (filter_model) {
url += '&filter_model=' + encodeURIComponent(filter_model);
}
var filter_price = $('input[name=\'filter_price\']').val();
if (filter_price) {
url += '&filter_price=' + encodeURIComponent(filter_price);
}
var filter_quantity = $('input[name=\'filter_quantity\']').val();
if (filter_quantity) {
url += '&filter_quantity=' + encodeURIComponent(filter_quantity);
}
var filter_status = $('select[name=\'filter_status\']').val();
if (filter_status != '*') {
url += '&filter_status=' + encodeURIComponent(filter_status);
}
var filter_image = $('select[name=\'filter_image\']').val();
if (filter_image != '*') {
url += '&filter_image=' + encodeURIComponent(filter_image);
}
var filter_date = $('input[name=\'filter_date\']').val();
if (filter_date) {
url += '&filter_date=' + encodeURIComponent(filter_date);
}
location = url;
});
//--></script>
<script type = "text/javascript">
function update(editableObj, column, product_id)
{
// if(confirm('Are you sure Update this data?'))
// {
//console.log(editableObj, column, product_id);
// return false;
$.ajax({
url: "index.php?route=catalog/product/update&token=<?php echo $token; ?>",
type: "POST",
//dataType: "JSON",
data: "column="+column+"&value="+editableObj.innerHTML+"&product_id="+product_id,
success: function(data) {
// set updated value as old value
$(editableObj).attr('data-old_value',editableObj.innerHTML);
//$(editableObj).css("background","#FDFDFD");
console.log(data);
},
// error: function (data) {
// console.log(data);
// }
});
// }
}
</script>
<script type="text/javascript"><!--
$('input[name=\'filter_name\']').autocomplete({
'source': function(request, response) {
$.ajax({
url: 'index.php?route=catalog/product/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent(request),
dataType: 'json',
success: function(json) {
response($.map(json, function(item) {
return {
label: item['name'],
value: item['product_id']
}
}));
}
});
},
'select': function(item) {
$('input[name=\'filter_name\']').val(item['label']);
}
});
$('input[name=\'filter_model\']').autocomplete({
'source': function(request, response) {
$.ajax({
url: 'index.php?route=catalog/product/autocomplete&token=<?php echo $token; ?>&filter_model=' + encodeURIComponent(request),
dataType: 'json',
success: function(json) {
response($.map(json, function(item) {
return {
label: item['model'],
value: item['product_id']
}
}));
}
});
},
'select': function(item) {
$('input[name=\'filter_model\']').val(item['label']);
}
});
//--></script></div>
<?php echo $footer; ?>
Controller File.
public function update()
{
$this->load->language('catalog/product');
//$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('catalog/product');
// print_r(strip_tags($this->request->post['product_id']));
// print_r($this->request->post['column']);
// print_r(strip_tags(trim($this->request->post['value'])));
// die;
$product_id = strip_tags($this->request->post['product_id']);
$column = $this->request->post['column'];
$editableobj = strip_tags(trim($this->request->post['value']));
$this->model_catalog_product->updateProduct($product_id, $column, $editableobj);
}
Error Report
[52price7897
index.php?route=catalog/product&token=4IEByubsLQVVEvXwKEaL0hytqZose2Wj:1006 52quantity<span class="label label-warning">9878970</span>][1]
strip_tags(html_entity_decode($result['name'],ENT_QUOTES,'UTF-8')) use this one, in $result['name'] give your varaibale name, it will work, you need to also use html_entity_decode function This code is working thanks karthickeyan

Unable to use Jquery.load() feature properly

I am trying to filter results that will be displayed to user based on selection, but, its not displaying, properly, I do not know what I am doing wrong. I process using GET on the same page (users.php?rid=). This is how it displays when I select a value. Seems it loads the page twice into the div
The Select Button
<select name="role_id" id="role_id" style="width: 150px;"
onchange="">
<option value="">Select User</option>
<?php
$rid = 0;
if (isset($_GET['rid'])) {
$rid = clean($_GET['rid']);
}
$roles = get_user_roles();
foreach ($roles as $row):
?>
<option
value="<?php echo $row['role_id']; ?>"<?php if (isset($rid) && $rid == $row['role_id']) echo 'selected'; ?>>
<?php echo $row['name']; ?>
</option>
<?php endforeach; ?>
</select>
RESULT DIV
<div id="filter_result">
<table class="table table-striped" >
<thead>
<tr>
<th><div>#</div></th>
<th><div>Name</div></th>
<th><div>Email</div></th>
<th><div>User Type</div></th>
<th><div>Options</div></th>
</tr>
</thead>
<tbody>
<?php
if ($rid < 1) {
$users = get_users();
} else {
$users = get_role_users($rid);
}
if ($users->num_rows < 1) {
echo '<div class = "alert alert-warning text-center">There are no Students for this Class.... <a class="btn btn-primary btn-sm" href="add_user.php">Add User</a></div>';
}
$count = 1;
foreach ($users as $row):?>
<tr>
<td><?php echo $count++; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo get_role_name($row['role_id']); ?></td>
<!--Options-->
<td>
<!--Change Role-->
<div class="btn-group">
<button type="button" class="btn btn-primary btn-sm dropdown-toggle"
data-toggle="dropdown">
Change Role <span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-default pull-right" role="menu">
<?php $roles = get_user_roles();
foreach ($roles as $row2):
?>
<li>
<a href="change_roles.php?rid=<?php echo $row2['role_id'].'&uid='.$row['user_id'];?>">
<?php echo $row2['name']; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<!--Delete Student-->
<a href="delete_user.php?id=<?php echo $row['user_id']; ?>"
onclick="confirm('Are You sure?')" class="btn btn-danger"> Delete</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div
JAVASCRIPT
<script>
$(document).on('change', 'select#role_id', function () {
var role_id = $(this).val();
$('#filter_result').load('users.php?rid='+role_id, '#filter_result');
});
</script>
It should display like this
Since you are Checking selection on the same page, you can assign id to your body tag, for example
<body id="page_body">
then use #page_body.load(), it will work
$('#page_body').load('users.php?rid='+role_id, '#filter_result');

PHP Looping Javascript Just Show The First Record

I have a view code:
<?php
$i = 1;
//var_dump($this->productList);
foreach ($this->productList as $data) {
$desc=explode(",",$data['descriptions']);
?>
<tr>
<th colspan="3">
<input type="hidden" id="id_pack" name="id_pack" value="<?php echo $data['package_id']; ?>">
<input type="hidden" id="nama_pack" name="nama_pack" value="<?php echo $data['package_name']; ?>">
<h4 align="center" class="title-pack"><?php echo $data['package_name']; ?></h4>
</th>
</tr>
<tr id="dashe">
<td>
<ul class="myul">
<?php foreach($desc as $descriptions) { ?>
<li class="myli"> <?php echo $descriptions; ?></li>
<?php } ?>
</ul>
</td>
<td>
<h4 class="prize">
Rp. <?php echo number_format($data['price'],2);?>
/ month
</h4>
</td>
<td>
<p id="order" name="order" class="mybutton" data-toggle="modal" data-target=".mymodal">Order</p>
</td>
</tr>
<?php
$i++;
}
?>
And this the javascript:
document.getElementById("order").addEventListener("click", tampilkanHrm);
function tampilkanHrm() {
var pilihan=$("#nama_pack").val();
document.getElementById("choice").innerHTML = pilihan;
document.getElementById("pack").value = pilihan+" Package";
}
the problem is, in the order button it always show the same record. Just show the first data, even i clicked other order button. Hope somebody help.
You can't assign same id for multiple elements.
So, have different ids.
<?php
$i = 1;
//var_dump($this->productList);
foreach ($this->productList as $data) {
$desc=explode(",",$data['descriptions']);
?>
<tr>
<th colspan="3">
<input type="hidden" id="id_pack<?php echo $i ?>" name="id_pack" value="<?php echo $data['package_id']; ?>">
<input type="hidden" id="nama_pack<?php echo $i ?>" name="nama_pack" value="<?php echo $data['package_name']; ?>">
<h4 align="center" class="title-pack"><?php echo $data['package_name']; ?></h4>
</th>
</tr>
Similarly create buttons with different ids.
<td>
<p id="<?php echo $i ?>" name="order" class="mybutton" data-toggle="modal" data-target=".mymodal">Order</p>
</td>
Then change your javascript to jquery. Hope, you might also be using jquery [ understood from your code ]
$(".mybutton").on("click", function() {
var identifier = $(this).attr("id");
var pilihan=$("#nama_pack"+identifier).val();
$("#choice").html(pilihan);
});
Change your code like this and check.

magento edit quantity without redirecting to another page

we have a marketplace site. each seller/vendor have their own account.
we are displaying list of sellers products , qty, sku...etc in their account.
http://prntscr.com/8vgul0
we are using this code to display those information :
<?php
$isPartner= Mage::getModel('marketplace/userprofile')->isPartner();
$helper= Mage::helper('marketplace');
if($isPartner==1){
?>
<script type="text/javascript">
if (typeof jQuery == 'undefined'){
document.write(unescape("%3Cscript src='//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
<script src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<div class="page-title">
<h1 style="float:left;"><?php echo $helper->__('My Product List') ?></h1>
</div>
<div class="wk_mp_design">
<div class="block block-account">
<div class="block-title">
<strong><span><h4><?php echo $helper->__('Product List') ?></h4></span></strong>
</div>
</div>
<div class="fieldset wk_mp_fieldset">
<div class="grid">
<div class="hor-scroll">
<form action="<?php echo Mage::helper('core/url')->getCurrentUrl();?>" method="post">
<table cellspacing="0" class="border wk_mp_list_table">
<thead>
<tr id="wk_mp_tr_heading">
<th><span><?php echo $helper->__('Product Name') ?></span></th>
<th><span><?php echo $helper->__('Date') ?></span></th>
<th><span><?php echo $helper->__('Product Status') ?></span></th>
<th><span> </span></th>
</tr>
</thead>
<tbody class="wk_mp_body">
<tr>
<td>
<input type="text" class="input-text" name="s" placeholder='<?php echo $helper->__('Search by product name') ?>' value="<?php echo $this->getRequest()->getParam('s')?>"/>
</td>
<td>
<span class="wk_mp_td_span">
<?php echo $helper->__('From: ') ?>
<input name="from_date" id="special_from_date" class="input-text" value="<?php echo $this->getRequest()->getParam('from_date')?>" />
</span>
<span class="wk_mp_td_span">
<?php echo $helper->__('To: ') ?>
<input name="to_date" id="special_to_date" class="input-text" value="<?php echo $this->getRequest()->getParam('to_date')?>" />
</span>
</td>
<td>
<select name="prostatus" class="input-text">
<option value=""><?php echo $helper->__('All') ?></option>
<option value="1" <?php if($this->getRequest()->getParam('prostatus') == 1) echo 'selected="selected"'?>>
<?php echo $helper->__('Approved') ?>
</option>
<option value="2" <?php if($this->getRequest()->getParam('prostatus') == 2) echo 'selected="selected"'?>>
<?php echo $helper->__('Unapproved') ?>
</option>
</select>
</td>
<td>
<button class="button" title="Save" type="submit">
<span><span><span><?php echo $helper->__('Submit') ?></span></span></span>
</button>
</td>
</tr>
</tbody>
</table>
</form>
<?php
if(count($this->getCollection())==0){ ?>
<div class="fieldset wk_mp_fieldset">
<div class="wk_emptymsg">
<?php echo $helper->__('No Product Available') ?>
</div>
</div>
<?php
} else{ ?>
<form action="<?php echo $this->getUrl('marketplace/marketplaceaccount/massdeletesellerpro') ?>" method="post" id="formmassdelete" name="formmassdelete">
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
<button class="button" title="<?php echo $helper->__('Delete Products') ?>" type="submit" style="float: left;padding: 5px 5px 5px 0;" id="mass_delete_butn">
<span><span><?php echo $helper->__('Delete Products') ?></span></span>
</button>
<table cellspacing="0" class="border wk_mp_list_table wk_mp_list_container_table">
<thead>
<tr class="wk_content">
<th class="wk_check_first_td">
<span>
<input type="checkbox" name="mpselecctall" value="all" id="mpselecctall"/>
</span>
</th>
<th class="wk_first_td">
<span class="label name">
<?php echo $helper->__('Product')?>
</span>
</th>
<th class="wk_first_td">
<span class="label name">
<?php echo $helper->__('sku')?>
</span>
</th>
<th>
<span class="label pro_status">
<?php echo $helper->__('Status')?>
</span>
</th>
<!--
<th>
<span class="label qty">
<?php echo $helper->__('Qty. Confirmed')?>
</span>
</th>
<th>
<span class="label qty">
<?php echo $helper->__('Qty. Pending')?>
</span>
</th>
<th>
<span class="label qty">
<?php echo $helper->__('Qty. Sold')?>
</span>
</th>
-->
<th>
<span class="label">
<?php echo $helper->__('Qty')?>
</span>
</th>
<th>
<span class="label">
<?php echo $helper->__('Earn Amount')?>
</span>
</th>
<th>
<span class="label">
<?php echo $helper->__('Action')?>
</span>
</th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach($this->getCollection() as $products){
$i++;
$productMediaConfig = Mage::getModel('catalog/product_media_config');
$salesdetail=Mage::getModel('marketplace/saleslist')->getSalesdetail($products->getEntityId());
?>
<tr class="wk_row_view <?php echo $class = ($i == count($this->getCollection()))? 'wk_last_tr':''?>">
<td class="wk_check_first_td">
<span>
<input type="checkbox" name="product_mass_delete[]" class="mpcheckbox" value="<?php echo $products->getEntityId(); ?>"/>
</span>
</td>
<td class="wk_first_td">
<input type="hidden" class="hidden_id" value="<?php echo $products->getEntityId(); ?>" />
<div class="label name" title="<?php echo $products->getName(); ?>">
<div class="wk_pro_divide1">
<img src="<?php echo Mage::helper('catalog/image')->init($products,'thumbnail');?>" class="image" />
</div>
<div class="wk_pro_divide2">
<div style="width:100%;">
<a href="<?php echo $this->getUrl($products->getUrlPath())?>" target="blank">
<?php echo $products->getName();?>
</a>
</div>
<div style="width:100%;float:left;">
<?php echo Mage::helper('core')->currency($products->getPrice(), true, false);?>
</div>
</div>
</div>
</td>
<td>
<?php echo $sku = Mage::getModel('catalog/product')->load($products->getId())->getSku();?>
</td>
<?php
if($products->getStatus()==2) { ?>
<td>
<span class="label pro_status">
<?php echo $helper->__('Pending')?>
</span>
</td>
<td>
<span class="label qty">
<?php echo $helper->__('Pending')?>
</span>
</td>
<td>
<span class="label qty">
<?php echo $helper->__('Pending')?>
</span>
</td>
<td>
<span class="label qty">
<?php echo $helper->__('Pending')?>
</span>
</td>
<td>
<span class="label qty">
<?php echo $helper->__('Pending')?>
</span>
</td>
<?php }
else{
$id=$products->getId();
$productsolddetail=Mage::getModel('marketplace/saleslist')->getProductSalesDetailById($id);
$qtycom=0;
$com=0;
foreach($productsolddetail as $key){
$qtycom+=$key['magequantity'];
$com+=$key['actualparterprocost'];
} ?>
<td>
<span class="label pro_status">
<?php echo $helper->__('Approved')?>
</span>
</td>
<!-- edit qty -->
<td>
<?php echo (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($products)->getQty(); ?>
<span class="label wk_action">
<img src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>" data-type="<?php echo $products->getTypeId(); ?>" alt="<?php echo $helper->__('Edit')?>" title="<?php echo $helper->__('Edit')?>" class="mp_edit"/>
</span>
</td>
<!-- edit qty end -->
<!--
<td>
<span class="label qty">
<?php echo $salesdetail['quantitysoldconfirmed']; ?>
</span>
</td>
<td>
<span class="label qty">
<?php echo $salesdetail['quantitysoldpending']; ?>
</span>
</td>
<td>
<span class="label qty">
<?php echo $salesdetail['quantitysold']; ?>
</span>
</td>
-->
<td>
<span class="label price">
<?php echo Mage::helper('core')->currency($salesdetail['amountearned'], true, false); ?>
</span>
</td>
<?php
}?>
<td>
<span class="label wk_action">
<img src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>" data-type="<?php echo $products->getTypeId(); ?>" alt="<?php echo $helper->__('Edit')?>" title="<?php echo $helper->__('Edit')?>" class="mp_edit"/>
<img src="<?php echo $this->getSkinUrl('marketplace/images/icon-trash.png'); ?>" alt="<?php echo $helper->__('Delete')?>" title="<?php echo $helper->__('Delete')?>" class="mp_delete"/>
</span>
</td>
</tr>
<?php
}?>
</tbody>
</table>
</form>
<?php
}?>
</div>
</div>
<?php echo $this->getPagerHtml(); ?>
</div>
<div class="buttons-set">
<p class="back-link">
« <?php echo $helper->__('Back') ?>
</p>
</div>
</div>
<script>
var $wk_jq=jQuery.noConflict();
var newCustomerProductForm1 = new VarienForm('formmassdelete', true);
(function($wk_jq){
$wk_jq( "#special_from_date" ).datepicker({dateFormat: "yy-mm-dd"});
$wk_jq( "#special_to_date" ).datepicker({dateFormat: "yy-mm-dd"});
$wk_jq('body').delegate('.mp_edit','click',function(){
var id=$wk_jq(this).parents('.wk_row_view').find('.hidden_id').val();
var dicision=confirm('<?php echo $helper->__(" Are you sure you want to edit this product ? ")?>');
if(dicision==true){
var $type_id=$wk_jq(this).attr('data-type');
if($type_id=='simple')
window.location = "<?php echo $this->getUrl('marketplace/marketplaceaccount/editapprovedsimple/') ?>".concat("id/",id);
if($type_id=='downloadable')
window.location = "<?php echo $this->getUrl('marketplace/marketplaceaccount/editapproveddownloadable/') ?>".concat("id/",id);
if($type_id=='virtual')
window.location = "<?php echo $this->getUrl('marketplace/marketplaceaccount/editapprovedvirtual/') ?>".concat("id/",id);
if($type_id=='configurable')
window.location = "<?php echo $this->getUrl('marketplace/marketplaceaccount/editapprovedconfigurable/') ?>".concat("id/",id);
if($type_id=='grouped')
window.location = "<?php echo $this->getUrl('mpgroupproduct/index/editapprovedgrouped/') ?>".concat("id/",id);
<?php
//echo $this->getChildHtml('mpgrouped_productslist');
// echo $this->getChildHtml('mpbundle_productslist');
?>
if($type_id=='bundle')
window.location = "<?php echo $this->getUrl('mpbundleproduct/index/editbundle/') ?>".concat("id/",id);
}
});
$wk_jq('#mass_delete_butn').click(function(e){
var flag =0;
$wk_jq('.mpcheckbox').each(function(){
if (this.checked == true){
flag =1;
}
});
if (flag == 0){
alert("<?php echo $helper->__(' No Checkbox is checked ') ?>");
return false;
}
else{
var dicisionapp=confirm('<?php echo $helper->__(" Are you sure you want to delete these product ? ")?>');
if(dicisionapp==true){
$wk_jq('#form-customer-product-new').submit();
}else{
return false;
}
}
});
$wk_jq('#mpselecctall').click(function(event) {
if(this.checked) {
$wk_jq('.mpcheckbox').each(function() {
this.checked = true;
});
}else{
$wk_jq('.mpcheckbox').each(function() {
this.checked = false;
});
}
});
$wk_jq('.mp_delete').click(function(){
var id=$wk_jq(this).parents('.wk_row_view').find('.hidden_id').val();
var dicisionapp=confirm('<?php echo $helper->__(" Are you sure you want to delete this product ? ")?>');
if(dicisionapp==true)
window.location = "<?php echo $this->getUrl('marketplace/marketplaceaccount/delete/') ?>".concat("id/",id);
});
})($wk_jq);
</script>
<?php
}else{
echo "<h2 class='wk_new_msg'>".$helper->__("To BECOME SELLER PLEASE CONTACT TO ADMIN.")."</h2>";
}?>
we have a edit button next to "Qty", if we click on that edit button, its redirecting to another page and than seller edit the information and save it.
we are using following code to edit :
<span class="label wk_action">
<img src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>" data-type="<?php echo $products->getTypeId(); ?>" alt="<?php echo $helper->__('Edit')?>" title="<?php echo $helper->__('Edit')?>" class="mp_edit"/>
</span>
what we need is if we click on "edit" button, then it should display text field as like in the image and update and cancel button below.
Please refer below URL for admin grid:
http://www.atwix.com/magento/inline-editing-in-magento-backend-grids/
I'm not sure but this may help you. Try below for front-end :
Step 1 : Make onclick event on your edit image and call javascript function
eg : onclick="updateField(this, '. $product_id .'); return false";
Step 2 : Create javascript function which you have define in onclick of image.
<?php $url='Mage::getUrl('module_name/index/updateField/');' ?>
<script type="text/javascript">
function updateField(image, product_id)
{
new Ajax.Request('<?php echo $url ?>', {
method: 'post',
parameters: { id: fieldId, field: $(button).previous('input').getValue() }
});
}
</script>
Step: 3 Make function in your controller that you have define in java script ajax url.
public function updateFieldAction()
{
$fieldId = (int) $this->getRequest()->getParam('id');
$field = $this->getRequest()->getParam('field');
if ($fieldId) {
$model = Mage::getModel('modulename/model')->load($fieldId);
$model->setField($field);
$model->save();
}
}

Categories