iam trying to update image through on change event in codeigniter
and want to update with different id each time when i select the image different. please help with the solution thanks in advance
Each time the product_image_id should change according to db table
$(document).ready(function(){
$('.images').on('change',function(){
var link = '<?php echo site_url('menu_management_con/editimage');?>';
var product_image_id = $('.id').val();
var formData= new FormData();
var file = this.files[0];
formData.append('file', file);
formData.append('product_image_id',product_image_id);
$.ajax({
type:'POST',
url: link,
data : formData,
cache: false,
processData:false,
contentType:false,
success:function(data){
alert(data);
}
});
});
});
this is my html code
am trying to update image through on change event in codeigniter
<form id="add_produc" method="post" class="addProduct" name="add_produc" action="<?=base_url()."menu/product_edit/".$data['product_id'].'/'.$data['category_id'] ?>" enctype="multipart/form-data" >
<div class="row">
<div class="col-sm-12">
<table class="table table-bordered">
<tr>
<th class="head" colspan="2">Edit</th>
</tr>
<tr>
<td><label for="Name">Name:</label></td>
<td>
<input type="text" name="product_name" value="<?= $data['product_name']?>" id="product_name" class="form-control" placeholder="Name">
</td>
</tr>
<tr>
<td> <label for="Description">Description:</label> </td>
<td>
<input type="text" name="product_description" value="<?= $data['product_description']?>" id="product_description" class="form-control" placeholder="description">
</td>
</tr>
<tr >
<td><label for="Photo">Photo:</label> </td>
<td>
<div id="addField0">
<input type="file" name="product_photo[]" multiple id="product_photo" class="form-control" accept="image/*"><br>
</div>
<button id="add-more-edit" name="add-more-edit" class="btn btn-primary">Add More</button>
</td>
</tr>
<?php
if(!empty($image)){
foreach ($image as $result){
?>
<tr class='imagelocation<?= $result->product_image_id ?>'>
<td colspan="2" align='center'>
<input type="text" name="product_image_id" value="<?= $result->product_image_id?>" id="product_photo" class="form-control id" >
<input type="file" name="image" id="image" class="form-control images" accept="image/*">
<img class='img-rounded' height="50" width="50" src="<?= base_url('/assets/uploads/products/'.$result->product_photo)?>" style="vertical-align: middle;">
<span style="cursor:pointer;" onclick="javascript:deleteimage(<?php echo $result->product_image_id ?>)">X</span>
</td>
</tr>
<?php
}
}else{
echo '<div class="empty">No Products Found...!</div>';
}
?>
<tr>
<td colspan="2">
<input type="hidden" name="sub_category_id" value="<?= $data['sub_category_id']?>" id="sub_category_name" class="form-control">
<input type="submit" name="update_product" id="update_product" class="btn btn-info btn-small" value="Update">
</td>
</tr>
</table>
</div>
</div>
</form>
Related
I am trying to validate the mobile number, email, firstname and etc.. field by using required and pattern keyword but its not responding anything.
In my program there is one input field for mobile number if user has entered mobile number which is not stored in database, then registration page pops up and user should registered for further process and if they entered mobile number which is stored in database then random number is displayed, but when I am entering the values in registration form but it is not validating like I have return required keyword in input field but still its not responding.
Please help me out of this.
Below us my code:
HTML
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<body>
<div>
<form action = "#" method = "post" >
<div>
<legend >Login</legend>
<table id="verify_table" cellpadding="2" cellspacing="2" >
<tr>
<td> Mobile No. </td>
<td><input id="mob" type="tel" name="mobile" required pattern="\[7-9]{1}[0-9]{9}\" /></td>
<td><input type="button" name="verify" class="verify" value="Verify"></td>
</tr>
</table>
</div>
<div id="random" style="display: none;" >
<table id='random_table'>
<tr>
<td>Random Number generated</td>
<td id='rand'>
</tr>
</table>
</div>
<!--Register pop up-->
<div id="reg_light" class="white_content">
<div id="register-title">
<div id="reg-title">
<h6>Register</h6>
</div>
<div id="close">
<a href="javascript:void(0)" onclick="document.getElementById('reg_light').style.display='none';
document.getElementById('fade').style.display='none'; $('#firstname').val('');
$('#lastname').val('');
$('#mobile_number').val('');
$('#email').val('');">X</a>
</div>
</div>
<?php //echo form_open('register'); ?>
<div id="register-inner">
<form id="reg_form" method="POST">
<table id="register_table">
<tr><td><font color="red">* Fields are mandatory</font></td></tr>
<!--<form id="reg_form" onSubmit="return formValidation();">-->
<tr>
<table id="name">
<tr>
<td>First Name<font color="red">*</font></td>
<td><input id="firstname" type="text" placeholder="First Name" name="firstname" required pattern="[A-Za-z]+" ></td>
<td>Last Name<font color="red" >*</font></td>
<td> <input id="lastname" type="text" placeholder="Last Name" name="lastname" required pattern="[A-Za-z]+"></td>
</tr>
</table>
</tr>
<tr><td>  </td></tr>
<tr>
<table id="gen">
<tr>
<td>Gender<font color="red">*</font></td>
<td><input type="radio" name="gender" value="Male"> Male</td>
<td><input type="radio" name="gender" value="Female"> Female</td>
</tr>
</table>
</tr>
<tr>
<table id="mob">
<tr>
<td>Mobile No.<font color="red">*</font></td>
<td><input id="mobile_number" type="text" placeholder="Mobile number" name="mobile_number" required pattern="[7-9]{1}[0-9]{9}" /></td>
<td>Email id<font color="red">*</font></td>
<td> <input id="email" type="email" placeholder="Email-id" name="email" required pattern="[A-Za-z]+[0-9]+#[A-Za-z]+.[A-Za-z]+"> </td>
</tr>
</table>
<table id="submit">
<tr>
<td id="errorBox"></td>
<td><input class="reg_data" id="submit" type="button" name="submit" value="Register"></td>
</tr>
</table>
</tr>
</table>
</form>
</div>
</body>
</html>
Here is my jQuery code
$(document).ready( function() {
$('.verify').click(function(){
var mob = $('#mob').val();
//alert(mob);
$.ajax({
url: "<?php echo base_url(); ?>/login/verify",
data: {'mob_no': mob},
type: "post",
cache: false,
success: function (data)
{
//alert(data);
var obj = $.parseJSON(data);
var fi="";
var otp="";
var rand="";
rand+=Math.floor(100000 + Math.random() * 99999);
$.each(obj, function()
{
fi=this['id'];
});
if(!fi=="")
{
//document.getElementById("random").innerHTML=random_number;
$('#rand').val(rand);
document.getElementById("rand").innerHTML=rand;
document.getElementById('random').style.display='block';
}
else
document.getElementById('reg_light').style.display='block';
document.getElementById('fade').style.display='block';
//alert(fi);
}
},
error: function (xhr, ajaxOptions, thrownError) {
//alert(thrownError);
}
});
});
});
Reset the form validation, after making the form visible
function resetFormValidator(formId) {
$(formId).removeData('validator');
$(formId).removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse(formId);
}
For Dynamically created dom
Use
$(document).on('click','#id',function(){
// do somethings
})
I'm trying to send text from my <td> with my simple ajax to my controller (I'm using Codeigniter).
Here is my HTML
<table class="table table-striped col-md-9 cstm">
<thead>
<tr>
<td> <strong>Transaction No</strong> </td>
<td> <strong> Line No </strong> </td>
<td> <strong>Item Code</strong> </td>
<td> <strong>Item Name</strong> </td>
<td> <strong>Extra Remark</strong> </td>
<td> <strong>Extra Remark 2</strong> </td>
<td width="10%"> <strong>Item QTY</strong> </td>
<td width="10%"> <strong>Receive QTY</strong> </td>
<td width="10%"> <strong>UOM Code</strong> </td>
<td width="10%"> <strong>Extra Remark Receipt</strong> </td>
</tr>
</thead>
<tbody>
<tr>
<td class="notrans">DORD-DK-M-TAM-69</td>
<td>1000 <input value="1000" type="hidden" name="LineNo[]" /> </td>
<td>S160291 <input value="S160291" type="hidden" name="ItemCode[]" /> </td>
<td>SMALL BAG <input value="SMALL BAG" type="hidden" name="ItemName[]" /> </td>
<td> <input value="" type="hidden" name="ExtraRemark[]" /></td>
<td> <input value="" type="hidden" name="ExtraRemark2[]" /></td>
<td>2 <input value="2.00000000000000000000" type="hidden" name="Quantity[]" /> </td>
<td><input required="required" type="text" value="2" name="recv_qty[]" /> </td>
<td> PCS<input type="hidden" value="PCS" name="uom[]" /> </td>
<td><input type="text" value="" name="ext_rmrk[]" /></td>
</tr>
<tr>
<td class="notrans">DORD-DK-M-TAM-70</td>
<td>2000 <input value="2000" type="hidden" name="LineNo[]" /> </td>
<td>S160288 <input value="S160288" type="hidden" name="ItemCode[]" /> </td>
<td>SMALL BAG <input value="SMALL BAG" type="hidden" name="ItemName[]" /> </td>
<td> <input value="" type="hidden" name="ExtraRemark[]" /></td>
<td> <input value="" type="hidden" name="ExtraRemark2[]" /></td>
<td>2 <input value="2.00000000000000000000" type="hidden" name="Quantity[]" /> </td>
<td><input required="required" type="text" value="2" name="recv_qty[]" /> </td>
<td> PCS<input type="hidden" value="PCS" name="uom[]" /> </td>
<td><input type="text" value="" name="ext_rmrk[]" /></td>
</tr>
</tbody>
</table>
<a class="pull-right btn btn-warning" id="update" href="#"> Update </a>
and here is my Jquery
$("#update").click(function(){
$this = $(this).val()
$.ajax({
data : { DetTrans : $('.notrans').text() },
url : "<?=base_url();?>dr_mutasi/updateEditItem",
type : "POST",
dataType: 'JSON',
success: function(data) {
console.log(data);
}
})
});
and here is my PHP
function updateEditItem(){
extract(populateform());
echo $DetTrans;
}
So, With my script abobve . I get this from my console.log
DORD-DK-M-TAM-69DORD-DK-M-TAM-70
As you can see, from my table there are .notrans and both of them has different value. Can you tell me how to send via ajax with this format ?
DORD-DK-M-TAM-69;DORD-DK-M-TAM-70
so i can explode it later with my PHP. Thanks in advance.
$("#update").click(function(){var value="";
$(document).find('.notrans').each(function(){
value += (value.length > 0) ? ';' + $(this).text():$(this).text();
});
$.ajax({
data : { DetTrans : value},
url : "<?=base_url();?>dr_mutasi/updateEditItem",
type : "POST",
dataType: 'JSON',
success: function(data) {
console.log(data);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-striped col-md-9 cstm">
<thead>
<tr><td> <strong>Transaction No</strong> </td> </tr>
</thead>
<tbody>
<tr><td class="notrans">DORD-DK-M-TAM-69</td></tr>
<tr><td class="notrans">DORD-DK-M-TAM-70</td></tr>
<tr><td class="notrans">DORD-DK-M-TAM-71</td></tr>
<tr><td class="notrans">DORD-DK-M-TAM-72</td></tr>
</tbody>
</table>
<a class="pull-right btn btn-warning" id="update" href="#"> Update </a>
You can update your jquery to get the value of all td containing notrans class.
<script type="text/javascript">
$(function(){
var value = '';
$('.notrans').each(function(){
if(value.length > 0)
value = value + ';' + $(this).text(); // will give you the value.
else
value = $(this).text();
});
});
</script>
Use value to send the data through ajax.
I have nine text boxes wrapped in a form but when post to codeigniter controller, there are two specific text boxes have no value but they actually have.
Anyone encountered this issue before ? what is actually wrong ?
Form
<form name="frm_RRequest" id="frm_RRequest" action="<?php echo site_url('user/add_recommendation_request/'); ?>" method="post">
<tbody>
<tr>
<td class="col-left">Date</td>
<td class="col-middle"><input class="datepicker" type="text" name="txtStartDate" id="txtStartDate" class="datepicker" placeholder="Click to select a start date.."></td>
<td class="col-middle"><input class="datepicker" type="text" name="txtEndDate" id="txtEndDate" class="datepicker" placeholder="Click to select a end date.."></td>
<td class="col-right"><div class="error" id="error_date"> </div></td>
</tr>
<tr>
<td class="col-left">Travel time</td>
<td class="col-middle"><input type="text" class="ptTimeSelect input" name="txtStartTime" id="txtStartTime" placeholder="Click to select start time.." data-default-time="false"></td>
<td class="col-middle"><input type="text" class="ptTimeSelect input" name="txtEndTime" id="txtEndTime" placeholder="Click to select end time.." data-default-time="false"></td>
<td class="col-right"><div class="error" id="error_time"> </div></td>
</tr>
<tr>
<td class="col-left">Location</td>
<td class="col-middle-2"><input type="text" class="inputWithImge" name="txtStartLocation" id="txtStartLocation" onmouseover="display_text(this)" placeholder="Click the icon to select a start point"/><img src="<?php echo base_url('assets/images/search_icon.png'); ?>" class="location-icon" title="Click to show map" name="location-icon_start" value="StartLocation"/></td>
<td class="col-middle-2"><input type="text" class="inputWithImge" name="txtEndLocation" id="txtEndLocation" onmouseover="display_text(this)" placeholder="Click the icon to select a end point"/><img src="<?php echo base_url('assets/images/search_icon.png'); ?>" class="location-icon" title="Click to show map" name="location-icon_end" value="EndLocation" /></td>
<td class="col-right"><div class="error" id="error_location"> </div></td>
</tr>
<input type="hidden" name="txtStartLocation_Coordinates" id="txtStartLocation_Coordinates">
<input type="hidden" name="txtEndLocation_Coordinates" id="txtEndLocation_Coordinates">
</tbody>
</table>
</div>
<div><input type="button" class="button" id="btnGo" name="btnGo" value="Input detail" /> <span> << click this button if the travel time and location(s) are different for each day</span></div>
<div id="detail">
</div>
<input type="hidden" name="txtTotalDetail" id="txtTotalDetail">
<input type="hidden" name="txtNoOfDays" id="txtNoOfDays">
<div> </div>
<div><input type="button" id="btn_SaveDetail" name="btn_SaveDetail" class="button" value="Save" /></div>
</form>
<script>
function display_text(obj){
var value = obj.value;
obj.title = value;
}
</script>
Controller :
$total_detail = $this->input->post("txtTotalDetail");
$noOfDays = $this->input->post("txtNoOfDays");
$userid = $this->session->userdata('id');
$start_date = $this->input->post("txtStartDate");
$end_date = $this->input->post("txtEndDate");
$start_time = $this->input->post("txtStartTime");
$end_time = $this->input->post("txtEndTime");
$start_location = $this->input->post("txtStartLocation");
$end_location = $this->input->post("txtEndLocation");
$start_location_coor = $this->input->post("txtStartLocation_Coordinates");
$end_location_coor = $this->input->post("txtEndLocation_Coordinates");
These two text boxes have no value :
$start_location = $this->input->post("txtStartLocation");
$end_location = $this->input->post("txtEndLocation");
It is possible you forgot to use $this->form_validation->set_rules() on those particular fields.
Put value in your input tag like
<input type="hidden" name="txtStartLocation_Coordinates" value ="<?php echo $this->input->post('txtStartLocation_Coordinates');?>" id="txtStartLocation_Coordinates">
<input type="hidden" name="txtEndLocation_Coordinates" value ="<?php echo $this->input->post('txtEndLocation_Coordinates');?>" id="txtEndLocation_Coordinates">
<script>
$(function(){
$('#txtStartLocation_Coordinates').val("your value");
$('#txtEndLocation_Coordinates').val("your value");
});
</script>
I am using ajax to updat codeigniter cart. My problem is when i add multiple items in the cart & update the quantity of items the quantity does not change. It only works for the last item added.
below is my code
<form id="columnarForm" name="columnarForm" enctype="multipart/form-data" method="post">
<table width="100%" align="center" cellpadding="0" cellspacing="0" class="table-responsive table-bordered table-hover">
<tbody>
<?php foreach($products as $product){ ?>
<tr>
<td align="right" valign="middle">
<input readonly type="text" name="name" value="<?php echo $product['name'] ?>"/>
</td>
<td align="right" valign="middle">
<input readonly type="text" name="price" value="<?php echo $product['price'] ?>"/>
</td>
<td align="right" valign="middle">
<input type="text" name="qty" value="<?php echo $product['qty'] ?>"/>
<input type="button" class="btn btn-primary btn-xs change" value="Change" />
</td>
<input type="hidden" name="rowid" value="<?php echo $product['rowid'] ?>"/>
</tr>
<script type="text/javascript">
$(function(){
$('.change').click(function(){
$.ajax({
type: "POST",
url: "<?php echo base_url()?>update-shopping-cart",
data: $("#columnarForm").serialize(),
beforeSend: function(){
$('#result').html('<img src="<?php echo site_url('assets/images/loading.gif'); ?>" class="center-block" />');
},
success: function(data){
$('#result').html(data);
}
});
});
});
</script>
<? } ?>
</tbody>
</table>
</form>
My Controller
// Updated the shopping cart
function updateCart(){
$data = array(
'rowid' => $this->input->post('rowid'),
'qty' => $this->input->post('qty'),
);
// Update the cart with the new information
$this->cart->update($data);
redirect(base_url().'update-cart-view');
}
You are looping through your products and setting all input names to be the same thing:
<td align="right" valign="middle">
<input readonly type="text" name="name" value="<?php echo $product['name'] ?>"/>
</td>
<td align="right" valign="middle">
<input readonly type="text" name="price" value="<?php echo $product['price'] ?>"/>
</td>
<td align="right" valign="middle">
<input type="text" name="qty" value="<?php echo $product['qty'] ?>"/>
So you end up with x amount of "name"s, x amount of "price"s and x amount of "qty"s. And your code grabs an element "name" with "price" with "qty". On submit, because all the inputs are in the same form, you send ALL of the information, but process only one set.
Either use the 'rowid' with every element name - 'price_rowid', 'name_rowid' and 'qty_rowid' so you can loop through all values, or loop through all post data on submit.
I'm trying to build an application using php. in "stock_out.php", i wanna create a form that include two barcodes. I have 8 fields. (1)Effectivedate,(2)Partnumber,(3)Description1,(4)Description2,(5)NPK,(6)Nama,(7)QtyOut,(8)Reason. I wanna using barcode-reader in "Partnumber" and "NPK".
I have some problems:
1. When i press enter, it's respon for button submit.
2. Actually, when i press enter in Partnumber, i want show details data in "description1" and "description2". As well as in NPK, i want show details data in "nama"
3. In the end of form, i still want to submit this form into database.
I'm newbie in AJAX, so i still don't know how to implementation AJAX in PHP. This is my code, I am grateful for the help
<html><body>
<div id="outerContainer">
<?php include("headerFile.html"); ?>
<?php include("navigationFile.html"); ?>
<div id="bodyContainer">
<div id="pageBodyTitle"> Stock Out </div> <br>
<form id="formSearch" name="formSearch" method="post" action="proses_out.php" onSubmit="return cek_data();">
<table id="messageTable">
<tr>
<td class="heading"> Effective Date </td>
<td>
<input class="inputField" name="tgl" type="text" readonly value="<?php echo $_POST['tgl']?>" tabindex="1"/>
<script language='JavaScript'>new tcal ({'formname': 'formSearch','controlname': 'tgl'});</script>
</td>
</tr>
<tr>
<td class="heading"> Part Number </td>
<td><input type='text' name='txtItem' id='txtItem' size="20" class="inputField" value='<?php echo $item;?>' tabindex="2" />
<img src='search.ico' onClick='open_win_item()'> </td>
</tr>
<tr>
<td class="heading">Description1</td>
<td><input type='text' name='txtDesc1' id='txtDesc1' size="50" value='<?php echo $desc1;?>' readonly /></td>
</tr>
<tr>
<td class="heading">Description2</td>
<td><input type='text' name='txtDesc2' id='txtDesc2' size="50" value='<?php echo $desc2;?>' readonly /></td>
</tr>
<tr>
<td class="heading"> NPK </td>
<td><input type='text' name='txtNpk' id='txtNpk' size="20" maxlength="5" class="inputField" value='<?php echo $tr_no;?>' tabindex="3" />
<img src='search.ico' onClick='open_win_npk()'></td>
</tr>
<tr>
<td class="heading">Nama</td>
<td><input type='text' name='txtName' id='txtName' size="30" value='<?php echo $nama;?>' readonly /></td>
</tr>
<tr>
<td class="heading"> Qty Out </td>
<td><input type='text' name='txtQty' id='txtQty' size="5" class="inputField" tabindex="4"/></td>
</tr>
<tr>
<td class="heading"> Reason </td>
<td><select class="inputField" name="choose" id="choose" value="" tabindex="5">
<?php
include "/class/connect_SQL.class.php";
$sql = "select reason_code from Inv_reason_master";
$query = mssql_query($sql);
while ($row = mssql_fetch_array($query))
{
$coba = $row['reason_code'];
?>
<option value="<?php echo $coba; ?>"><?php echo $coba;?></option>
<?php
}
?>
</select></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="Submit" value="Save" class="formButton2" tabindex="6"/>
<input type="reset" name="reset" value="Cancel" class="formButton2" tabindex="7"/>
</td>
</tr>
</table>
</form>
</div>
<?php
if(isset($_GET["message"]) and $_GET["message"]='save')
{
echo "<script language=\"javascript\"> alert('Data Tersimpan!') </script>";
}
?>
<?php include("footerFile.html"); ?>
</div>
You will have to prevent the response of the "Enter"-key. If you are using jquery in your project you can prevent it with this code:
$(function() {
$("form").bind("keypress", function(e) {
if (e.keyCode == 13) return false;
});
});
To bind Enter key to "Part number" field instead you could try this:
$('#txtItem').keypress(function(e) {
if (e.keyCode == 13) {
alert('Enter is pressed in part number');
}
});