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.
Related
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.
i have 2 Checkboxes (in each row) in my Table. I want to submit and update a row by pressing the checkbox and not with a submit button, it works, but i want it to submit without refreshing the whole page. I am using JS and AJAX for it, but this time, i'm making something wrong.
The first Checkbox:
<td>
<form id="checkgo" method="post">
<input type="checkbox" onchange="this.form.submit()" name="wegeb" id="wegeb" value="<?php echo $row['bestellnr'] ?>">
</form>
<?php echo $row['we_gebucht']; ?> </td>
The Script for it:
<script>
$(document).ready(function() {
$("#checkgo").submit(function (event){
event.preventDefault()
var wegeb = document.getElementById("wegeb").value
var info = {wegeb: wegeb};
$.ajax({
type : "POST",
url : "addlist.php",
data : info,
});
return false;
});
});
</script>
And the php file for the Update (addlist.php):
$we_gebucht = (isset($_POST['we_gebucht']) && !empty($_POST['we_gebucht'])) ? $_POST['we_gebucht'] : null;
$we_gebucht='yes';
$bestellnr = (isset($_POST['wegeb']) && !empty($_POST['wegeb'])) ? $_POST['wegeb'] : null;
$update=mysqli_query($connection,"UPDATE bestellung SET we_gebucht='$we_gebucht' WHERE bestellnr='$bestellnr'");
$result = $connection->query($update);
My understanding:
With "var wegeb = document.getElementById("wegeb").value" i'm selecting the Checkboxes Value (which contains the Key "bestellnr" from the table), that one i'm passing as wegeb to the addlist.php, where it gets in the Variable $bestellnr. Now, the row from the Key is getting updated.
Moreover, the page is still reloading, even with the event.preventDefault().
it's clear something is wrong, but i dont see where and tried different ways.
i hope i made my problem clear,
Thanks for any Help or tip!
Update(Table):
<tr>
<td> <?php echo $row['warennr']; ?> </td>
<td> <?php echo $row['kundeprojekt_id']; ?> </td>
<td> <?php echo $row['bestellnr']; ?> </td>
<td> <?php echo $row['besteller']; ?> </td>
<td> <?php echo $row['datum']; ?> </td>
<td> <?php echo $row['gesamtwert']; ?> </td>
<td> <?php echo $row['po_nr']; ?> </td>
<td> <?php echo $row['ebest_ekw']; ?> </td>
<td>
<form id="checkgo" method="post">
<input type="checkbox" name="wegeb" id="wegeb" value="<?php echo $row['bestellnr'] ?>">
</form>
<?php echo $row['we_gebucht']; ?> </td>
<td> <?php echo $row['PSP_Element']; ?> </td>
<td>
<form id='liefert' method="post" >
<input type="checkbox" onclick="doThis(this)" name="lief" id="lief" value="<?php echo $row['bestellnr'] ?>">
</form>
<?php echo $row['geliefert']; ?> </td>
<td> <?php echo $row['smarttrack']; ?> </td>
<td> <?php echo $row['name']; ?> </td>
<td> <?php echo $row['preis']; ?> </td>
<td> <?php echo $row['menge']; ?> </td>
<td> <?php echo $row['assetnr']; ?> </td>
<td> <?php echo $row['ticketnr']; ?> </td>
<td> <?php echo $row['Anlagennr']; ?> </td>
<td> <?php echo $row['lieferantname']; ?> </td>
<td> <?php echo $row['kostenstelle']; ?> </td>
<td> <?php echo $row['kundenname_projekt']; ?> </td>
<td> <?php echo $row['standort']; ?> </td>
<td> <?php echo $row['info_uebergabe']; ?> </td>
<td> <?php echo $row['warengruppe']; ?> </td>
<td> <button class="btn-update"> ✎ </button> </td>
<td> <button class="btn-deletee" type="button" id="<?php echo $row['bestellnr']; ?>" data-id2="<?php echo $row['warennr']; ?>" data-id3="<?php echo $row['kundeprojekt_id']; ?>" >Delete</a></button></td>
</tr>
First, let's remove the inline js from your html:
<td>
<form id="checkgo" method="post">
<input type="checkbox" name="wegeb" id="wegeb" value="<?php echo $row['bestellnr'] ?>">
</form>
<?php echo $row['we_gebucht']; ?>
</td>
Then we bind the ajax call to the right event:
$(function() {
$("#wegeb").change(function (e){
e.preventDefault(); //not necessary since we are binding to the checkbox
var wegeb = $(this).val();
var info = {wegeb: wegeb};
$.ajax({
type : "POST",
url : "addlist.php",
data : info,
});
});
});
This way every time you check the checkbox or uncheck it, it will update the database accordingly
You can prevent the form from submitting with e.preventDefault();, this is not good idea.
this may help you:-
<form id="checkgo" method="post">
<input type="checkbox" onchange="doThis(this)" name="wegeb" id="wegeb" value="<?php echo $row['bestellnr'] ?>">
</form>
<script>
function doThis(checkbox){
var wegeb = document.getElementById("wegeb").value
var info = {wegeb: wegeb};
$.ajax({
type : "POST",
url : "addlist.php",
data : info,
});
return false;
}
</script>
I have this controller:
<?php
class Cart extends CI_Controller{
public $paypal_data = '';
public $tax;
public $shipping;
public $total = 0;
public $grand_total;
/*
*Cart Index
*/
public function index(){
//Load view
$data['main_content'] = 'cart';
$this->load->view('layouts/main', $data);
}
/*
*Add To Cart
*/
public function add(){
//Item data
$data = array(
'id'=> $this->input->post('item_number'),
'qty'=> $this->input->post('qty'),
'price'=> $this->input->post('price'),
'name'=> $this->input->post('title'),
);
//print_r($data);die();
//Insert Into cart-block
$this->cart->insert($data);
redirect('products');
}
}
And I have the view file which uses this controller:
<div class="cart-block">
<form action="cart/update" method="post">
<table cellpadding="6" cellspacing="1" style="width:100%" border="0">
<tr>
<th>QTY</th>
<th>Item Description</th>
<th style="text-align:right">Item Price</th>
</tr>
<?php $i = 1; ?>
<?php foreach ($this->cart->contents() as $items) : ?>
<input type="hidden" name="<?php echo $i. '[rowid]'; ?>" value="<?php echo $items['rowid']; ?>" />
<tr>
<td><input type="text" name="<?php echo $i.'[qty]'; ?>" value="<?php echo $items['qty']; ?>" maxlength="3" size= "5"</td>
<td><?php echo $items['name']; ?></td>
<td style="text-align:right"><?php echo $this->cart->format_number($items['price']); ?></td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<tr>
<td></td>
<td class="right"><strong>Total</strong></td>
<td class="right" style="text-align:right">$<?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</table>
<br>
<p><button class="btn btn-default" type="submit">Update Cart</button>
<a class="btn btn-default" href="cart">Go To Cart</a></p>
</form>
</div>
<div class="panel panel-default panel-list">
<div class="panel-heading panel-jeading-dark">
<h3 class="panel-title">
Categories
</h3>
</div>
<!--List group -->
<ul class="list-group">
<?php foreach(get_categories_h() as $category) : ?>
<li class="list-group-item"><?php echo $category->name; ?></li>
<?php endforeach; ?>
</ul>
I apologize that I can't show you the actual website because it's not online but based on the above snippets can any point out an error in the view file or controller that causes the shopping cart not to update?
I'm following a video tutorial but it seems I'm doing something wrong. Here is the video: https://youtu.be/ajt_DJMS5FM?t=13m45s
Your form action is cart/update your function in the controller is add?
Change the form action to cart/add. Or write an cart/update function.
Firstly change the Form Action action="cart/update" to
action="<?php echo base_url();?>cart/add" and apply die(); and test it
load the cart library in controller
$this->load->library('cart');
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');
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();
}
}