Existing Product Code Check
- view page
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Product
Code<span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="pro_code" id="productcode" onkeyup="checkProductCode();" required
class="form-control col-md-7 col-xs-12" placeholder='Product Code' value="<?php echo $pro_code; ?>">
<div id="productcode_response" style="color:red;"></div>
</div>
</div>
- controller
// checkProductCode
function checkProductCode(){
$productcode = $this->input->post('productcode');
$this->db->select('pro_code');
$this->db->where('pro_code', $productcode);
$this->db->from('product');
$query = $this->db->get();
echo count($query->result());
// if($dd){
// print 1;
// }else{
// print 0;
// }
}
- js
<script>
function checkProductCode() {
var productcode = $('#productcode').val();
//console.log(productcode);
if (productcode != '') {
$.ajax({
url: '<?php echo base_url('
adminproducts / checkProductCode ');?>',
type: 'post',
data: {
productcode: productcode
},
success: function (data) {
// console.log(data);
if (data > 0) {
$("#productcode_response").html(
"<span class='not-exists'>* Product Code Already in use.</span>");
$("#productcode_response").show();
} else {
$("#productcode_response").hide();
}
}
});
}
}
</script>
Comments
Post a Comment