我有3個按鈕點擊每個按鈕,特定的提交表單將被顯示。我的問題是提交任何形式的消息後顯示「成功」,但它返回到第一個form.i希望窗體留在當前窗體本身。我可以做這個。請幫助。
這裏是我的代碼:提交表格後留下
<html>
<body>
<button type="button" id="incbutton" > Report1</button>
<button type="button" id="dthbutton" > Report2</button>
<button type="button" id="negbutton" > Report3</button>
<script type="text/javascript">
$("#incbutton").click(function() {
$("#form_sub_container1").show();
$("#form_sub_container2").hide();
$("#form_sub_container3").hide();
})
$("#dthbutton").click(function() {
$("#form_sub_container2").show();
$("#form_sub_container1").hide();
$("#form_sub_container3").hide();
})
$("#negbutton").click(function() {
$("#form_sub_container3").show();
$("#form_sub_container1").hide();
$("#form_sub_container2").hide();
})
</script>
<div id="form_sub_container1" style="display: block;">
//report1 functionalities
<input type="submit" name="rep1" value="Save" id="btnsize" /></td>
</div>
<div id="form_sub_container2" style="display: none;">
//report2 functionalities
<input type="submit" name="rep2" value="Save" id="btnsize" /></td>
</div>
<div id="form_sub_container3" style="display: none;">
//report3 functionalities
<input type="submit" name="rep3" value="Save" id="btnsize" /></td>
</div>
</body>
<html>
這是我的報告3:
<div id="form_sub_container3" style="display: none;">
<?php
if (isset($_POST['rep3']))
{
$daydropdown111=$_POST['daydropdown111'];
$monthdropdown111=$_POST['monthdropdown111'];
$yeardropdown111=$_POST['yeardropdown111'];
$dreport_place=$_POST['dreport_place'];
$dreport_address=$_POST['dreport_address'];
$dreport_additional=$_POST['dreport_additional'];
}
else
{
$daydropdown111="";
$monthdropdown111="";
$yeardropdown111="";
$dreport_place ="";
$dreport_address="";
$dreport_additional="";
}
if (isset($_POST['rep3']))
{
$death = $DataAccessController->death_reports($_POST['daydropdown111'],$_POST['monthdropdown111'],$_POST['yeardropdown111'],$_POST['dreport_place'], $_POST['dreport_address'], $_POST['dreport_additional']);
if ($death) {
echo"<p><font color=red size='5pt' > Your Report has been Registered</font></p>";
}
}
?>
<div id="color" >
<table>
<h1 align="center"><p> Report</h1>
<form action="" method="POST" id="form_id">
<tr><td>Date </td><td>
<select name="daydropdown111" id="daydropdown111"></select>
<select name="monthdropdown111" id="monthdropdown111"></select>
<select name="yeardropdown111" id="yeardropdown111"></select>
<script type="text/javascript">
//populatedropdown(id_of_day_select, id_of_month_select, id_of_year_select)
populatedropdown("daydropdown111", "monthdropdown111", "yeardropdown111")
</script>
</td></tr>
<tr><td></br> Place </td><td></br><select name="dreport_place"id="wgtmsr">
<option value="hospital" >Hospital</option><option value="residence">Residence</option><option value="others">Others</option></select></td></tr>
<tr><td>Address </td><td></br><textarea name="dreport_address" rows="5" cols="32" id="loc" value=""> </textarea></td></tr>
<tr><td>Additional Cases if any</td><td></br> <textarea name="dreport_additional" rows="5" cols="32" id="loc" value=""> </textarea></td></tr></label></td></tr>
<tr><td></td><td><input type="submit" name="rep3" value="Save" id="btnsiz" /></td></tr>
</form>
</table></br>
</div>
</div>
當您提交表單時,頁面是否再次加載?或者你使用AJAX? – void 2015-02-12 06:51:06
是的,它加載,我不希望它發生。我希望它留在同一頁上的消息顯示。和米不使用AJAX – jermina 2015-02-12 06:58:44
但爲此,你需要使用AJAX。 AJAX不會重新加載你的頁面,會使用戶停留在同一個表單上,並且也會很好地顯示消息。 – void 2015-02-12 07:00:18