0
這是我的問題'if(!empty($ _ POST ['btn_editinventory]))'正在工作,但如果我點擊btndeleteinventory它也會執行我的btneditinventory中的代碼。任何人都知道我怎麼會糾正我的狀態在我的控制器,如果你有這樣的看法兩個按鈕:控制器中的Codeigniter 2按鈕
<input type="button" value="Edit" name="btn_editinventory" id="btn_editinventory" onclick="validate_editinventory();"/>
<input type="button" value="Delete" name="btn_deleteinventory" id="btn_deleteinventory" onclick="validate_deleteinventory();"/>
預先感謝您的幫助! :)
這是我的看法
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/css/mystyle.css') ?>">
<div id="content">
<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 = $other2->Equipment;
$otherdesc = $other2->ItemDescription;
$otherID = $other2->ID;
$otherserialnum = $other2->SerialNumber;
?>
<td>Equipment</td>
<?php // if(isset($other)) { ?>
<td><input type="text" id="txt_editotherequip" name="txt_editotherequip" value="<?php echo $otherequips // echo (isset($other->Equipment) AND $other->Equipment) ? $other->Equipment:''; ?>"/></td>
<td>Item Description</td>
<td><input type="text" id="txt_editotherdesc" name="txt_editotherdesc" value="<?php echo $otherdesc // echo (isset($other->ItemDescription) AND $other->ItemDescription) ? $other->ItemDescription:''; ?>"/></td>
<td style="visibility: hidden;"><input type="text" id="txt_editotherID" name="txt_editotherID" value="<?php echo $otherID //echo (isset($other->ID) AND $other->ID) ? $other->ID:''; ?>"/></td>
</tr>
<tr>
<td>Serial Number</td>
<td><input type="text" id="txt_editotherserialnum" name="txt_editotherserialnum" value="<?php echo $otherserialnum // echo (isset($other->SerialNumber) AND $other->SerialNumber) ? $other->SerialNumber:''; ?>"/></td>
<?php // } ?>
</tr>
<tr>
<td><input type="button" id="btn_editother" name="btn_editother" value="Edit" onclick="validate_edit_otherequip();"/></td>
<td><input type="button" id="btn_deleteother" name="btn_deleteother" class="btn_deleteother" value="Delete" onclick="validate_delete_otherequip();"/></td>
</tr>
</table>
</fieldset>
</form>
</div>
這裏是我的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;
}
}
}
function validate_delete_otherequip(){
var x;
if(confirm("Are you sure you want to delete this data?") === true){
var x = document.forms['frm_otherequips2'].submit();
}
else if(confirm("Are you sure you want to delete this data?") === false){
return false;
}
}
,這裏是我的控制器:
public function edit_delete_others2($id){
$data_other['other2'] = $this->inventory_model->other_search($id);
$this->load->view('homeview');
$this->load->view('frm_otherequips2', $data_other);
$this->load->view('footer_view');
}
我不知道如何在按鈕中有條件。
你能發佈完整的html代碼嗎? – Searock
你如何提交表格? –
Searock我編輯了我的問題,現在可以看到我的整個程序。 –