的财产我都在JavaScript的条件,说如果文本框为空,将提醒并返回false,但它不工作,而不是将其提交这里是我的看法笨:试图让非对象
frm_otherequips2.php
<form action="edit_delete_others2" method="POST" id='frm_otherequips2' name="frm_otherequips2">
<fieldset id="edit_other">
<legend>Inventory Details</legend>
<table>
<tr>
<?php $otherequips = $other->Equipment;
$otherdesc = $other->ItemDescription;
$otherID = $other->ID;
$otherserialnum = $other->SerialNumber;
?>
<td>Equipment</td>
<td><input type="text" id="txt_editotherequip" name="txt_editotherequip" value="<?php echo $otherequips ?>"/></td>
<td>Item Description</td>
<td><input type="text" id="txt_editotherdesc" name="txt_editotherdesc" value="<?php echo $otherdesc ?>"/></td>
<td style="visibility: hidden;"><input type="text" id="txt_editotherID" name="txt_editotherID" value="<?php echo $otherID ?>"/></td>
</tr>
<tr>
<td>Serial Number</td>
<td><input type="text" id="txt_editotherserialnum" name="txt_editotherserialnum" value="<?php echo $otherserialnum ?>"/></td>
</tr>
<tr>
<td><button class="btn_editother" id="btn_editother" name="btn_editother" type="submit" value="Edit" onclick="validate_edit_otherequip();">Edit</button></td>
</tr>
</table>
</fieldset>
</form>
,这里是我的javascript:
<script>
function validate_edit_otherequip(){
if(document.getElementById('txt_editotherequip').value === ""){
alert('Please Input Equipment!');
return false;
}
else if(document.getElementById('txt_editotherdesc').value === ""){
alert('Please Input Item Description');
return false;
}
else if(document.getElementById('txt_editotherserialnum').value === ""){
alert('Please Input Serial Number');
return false;
}
else{
var y;
if(confirm("Are you sure you want to save updated data?") === true){
var y = document.forms['frm_otherequips2'].submit();
}
else if(confirm("Are you sure you want to save updated data?") === false){
return false;
}
}
}
</script>
我所做的是我把控制器返回false,这里是我的控制器:
public function edit_delete_others2($id){
$data_other['other'] = $this->inventory_model->other_search($id);
$this->load->view('homeview');
$this->load->view('frm_otherequips2', $data_other);
$this->load->view('footer_view');
if(!empty($_POST['btn_editother'])){
if($_POST['txt_editotherequip'] == "") {
return false;
}
else if($_POST['txt_editotherdesc'] == "") {
return false;
}
else if($_POST['txt_editotherserialnum'] == ""){
return false;
}
else{
$this->inventory_model->update_others($this->input->post());
redirect('inventorysys_controller/view_others', 'refresh');
}
}
}
但每次我运行它,我离开例如空白文本框“txt_editotherequip”是空白它张贴警告,然后这个错误发生:
**时遇到一个PHP错误
严重性:通知
消息:试图让非对象
文件名的属性:意见/ frm_otherequips2.php
行号:10
一个PHP错误遇到
严重性:注意
消息:试图让非对象的属性
文件名:观点/ frm_otherequips2.php
行号:11
遇到PHP错误
严重性:注意
消息:试图让非对象的属性
文件名:观点/ frm_otherequips2.php
行号:遇到12
一个PHP错误
试图获得非物件的财产
消息:试图获得非物件的财产
文件名:观点/ frm_otherequips2.php
行号:13 **
请你帮我在这一个,我一直坚持这个好几天。预先感谢您的帮助!
我用这个“echo(isset($ other-> Equipment)AND $ other-> Equipment)替换了”$ otherequips = $ other-> Equipment“?$ other-> Equipment:'';”当我按下编辑按钮和一个文本框是空白的时候,if条件在我看来是有效的,但是当我单击警告时确定,其他文本框也变成空白..尽管它没有提交。 –