The intention is edit an invioce based on the invoice_id value received from the selection of a particular invoice from the invoice list table. Since this is an edit form, the invoice related details should be pre-loaded from the database.
目的是根据从发票清单表中选择特定发票收到的invoice_id值来编辑invioce。由于这是一个编辑表单,因此应从数据库预先加载与发票相关的详细信息。
The code looks as follows:
代码如下:
$invoice_id= base64_decode($_REQUEST['invoice_id']);
require_once '../model/invoice.php';
$obj=new Invoice();
$val=mysql_fetch_assoc($obj->getInvoiceDetailsForEdit($invoice_id));
The HTML of the hidden input text field is:-
隐藏输入文本字段的HTML是: -
<input type="hidden" name="inv_no" id="inv_no" value="<?php echo $invoice_id ?>"/>
The Script that is to be triggered inorder to get the preselected category is:-
要获得预选类别而触发的脚本是: -
<script>
function getSelectedCategory(inv_no){
if(inv_no!==""){
var request = $.ajax({
url: "../controller/invoice.php",
type: "POST",
data: {inv_no:inv_no,action:'get_selected_category'},
dataType: "json"
});
request.done(function(json_return){
$('#category').val(json_return['category_code']);
});
request.fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
return false;
});
}
}
</script>
The Controller code:-
控制器代码: -
function getSelectedCategory(){
$inv=$_POST['inv_no'];
require_once '../model/invoice.php';
$obj=new Invoice();
$result=mysql_fetch_assoc($obj->getAllInvoiceDetailsForViewing($inv));
echo json_encode($result);
exit;
}
Everything is working perfectly except the fact that I don't know what to do to run the script after the php variable $invoice_id is being loaded since the text field cannot accept events as it is a hidden field..
一切都工作得很好,除了我不知道如何在加载php变量$ invoice_id之后运行脚本,因为文本字段不能接受事件,因为它是隐藏字段。
I had changed the code as similar to the below one and found it is working:
我已将代码更改为类似于下面的代码,并发现它正在工作:
<input type="text" name="inv_no" id="inv_no" value="<?php echo $invoice_id ?> onblur="getSelectedCategory(this.value)"/>
Any suggestions would be very helpful!!
任何建议都会非常有用!!
1 个解决方案
#1
0
have you tried this:
你试过这个:
function getSelectedCategory(inv_no){
window.onload = function(){
if(inv_no!==""){
var request = $.ajax({
url: "../controller/invoice.php",
type: "POST",
data: {inv_no:inv_no,action:'get_selected_category'},
dataType: "json"
});
request.done(function(json_return){
$('#category').val(json_return['category_code']);
});
request.fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
return false;
});
}
}
}
}
I have added window.onload
event to your JS function to make sure every element is loaded.
我已经将window.onload事件添加到您的JS函数中以确保每个元素都已加载。
#1
0
have you tried this:
你试过这个:
function getSelectedCategory(inv_no){
window.onload = function(){
if(inv_no!==""){
var request = $.ajax({
url: "../controller/invoice.php",
type: "POST",
data: {inv_no:inv_no,action:'get_selected_category'},
dataType: "json"
});
request.done(function(json_return){
$('#category').val(json_return['category_code']);
});
request.fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
return false;
});
}
}
}
}
I have added window.onload
event to your JS function to make sure every element is loaded.
我已经将window.onload事件添加到您的JS函数中以确保每个元素都已加载。