HTML-PHP、浏览器后退按钮和;这一页的确切历史
我正在开发一个使用HTML和PHP的网站。在我的HTML页面中,我有一个带有标记为“REQUIRED”字段的表单。因为这些字段是必需的,所以我将表单的submit按钮设置为disabled,直到填写完所有必需的字段。全部填充后,按钮将启用。按钮的行为取决于字段,可以正常工作。但是,当用户提交表单,然后单击浏览器的“返回”按钮(尝试返回表单)时,该按钮将被禁用,但所有必填字段都已填充。因此,它并没有真正回到页面的确切历史。这对用户来说也很烦人 我怎样才能解决这个问题?下面是我的HTML页面的一部分HTML-PHP、浏览器后退按钮和;这一页的确切历史,html,button,back,browser-history,Html,Button,Back,Browser History,我正在开发一个使用HTML和PHP的网站。在我的HTML页面中,我有一个带有标记为“REQUIRED”字段的表单。因为这些字段是必需的,所以我将表单的submit按钮设置为disabled,直到填写完所有必需的字段。全部填充后,按钮将启用。按钮的行为取决于字段,可以正常工作。但是,当用户提交表单,然后单击浏览器的“返回”按钮(尝试返回表单)时,该按钮将被禁用,但所有必填字段都已填充。因此,它并没有真正回到页面的确切历史。这对用户来说也很烦人 我怎样才能解决这个问题?下面是我的HTML页面的一部分
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
function checkChange()
{
var title_txt = document.getElementById('title_textarea').value.replace(/^\s+|\s+$/g,"");
var system_and_device_txt= document.getElementById('system_and_device_textarea').value.replace(/^\s+|\s+$/g,"");
var finding_txt = document.getElementById('finding_textarea').value.replace(/^\s+|\s+$/g,"");
var implication_txt = document.getElementById('implication_textarea').value.replace(/^\s+|\s+$/g,"");
var recommendation_txt = document.getElementById('recommendation_textarea').value.replace(/^\s+|\s+$/g,"");
if(document.getElementById('service_name_select').selectedIndex != '0' &&
document.getElementById('risk_rating_select').selectedIndex != '0' &&
document.getElementById('root_cause_select').selectedIndex != '0' &&
document.getElementById('impact_select').selectedIndex != '0' &&
document.getElementById('likelihood_select').selectedIndex != '0' &&
document.getElementById('efforts_select').selectedIndex != '0' &&
document.getElementById('client_name_select').selectedIndex != '0' &&
document.getElementById('project_name_select').selectedIndex != '0' &&
title_txt != "" &&
system_and_device_txt!="" &&
finding_txt != "" &&
implication_txt != "" &&
recommendation_txt != ""
)
document.getElementById('save_button').disabled = false;
else
document.getElementById('save_button').disabled = true;
}
</style>
</head>
<body>
<div class="page-out">
<div class="page-in">
<div class="page">
<div class="main">
<div class="header">
</div>
<div class="content">
<div class="content-left">
<div class="row1">
<?php
include "AccountHolder.php";
$database_manager = new DatabaseManager();
$database_manager ->connect();
$db_link = $database_manager ->get_connection();
?>
<form method="post" action= "save_record_page.php" >
<fieldset style='padding:15px'>
<legend>Insert New Data </legend>
<p> <font color='red'> * </font> Service Name :
<select name="service_name" id= "service_name_select" onchange="checkChange()">
<option value=""> -Select- </option>
<?php
$result = $db_link->query("SELECT * FROM servicetype_lookup ");
while($row= $result->fetch_row()) {
$id = $row[0];
$value = $row[1];
echo "<option value='$id'>$value</option>";
}
?>
</select>
</p>
<br/>
<font color='red'>*</font>
Title : <input type="text" name="title" id="title_textarea" oninput="checkChange()"/>
<br/>
<br/>
<font color='red'>*</font>
Risk Rating :
<select name="risk_rating" id= "risk_rating_select" onchange="checkChange()" >
<option value=""> -Select- </option>
<?php
$result = $db_link->query("SELECT * FROM riskrating_lookup ");
while($row= $result->fetch_row()) {
$id = $row[0];
$value = $row[1];
echo "<option value='$id'>$value</option>";
}
?>
</select>
<br />
<br/>
<font color='red'>*</font>
Root Cause :
<select name="root_cause" id= "root_cause_select" onchange="checkChange()">
<option value=""> -Select- </option>
<?php
$result = $db_link->query("SELECT * FROM rootcause_lookup ");
while($row= $result->fetch_row()) {
$id = $row[0];
$value = $row[1];
echo "<option value='$id'>$value</option>";
}
?>
</select>
<br/>
<br/>
<font color='red'>*</font>
Impact :
<select name="impact" id= "impact_select" onchange="checkChange()">
<option value=""> -Select- </option>
<?php
$result = $db_link->query("SELECT * FROM impact_lookup ");
while($row= $result->fetch_row()) {
$id = $row[0];
$value = $row[1];
echo "<option value='$id'>$value</option>";
}
?>
</select>
<br />
<br/>
<font color='red'>*</font>
Likelihood :
<select name="likelihood" id= "likelihood_select" onchange="checkChange()">
<option value=""> -Select- </option>
<?php
$result = $db_link->query("SELECT * FROM likelihood_lookup ");
while($row= $result->fetch_row()) {
$id = $row[0];
$value = $row[1];
echo "<option value='$id'>$value</option>";
}
?>
</select><br/><br/>
<font color='red'>*</font>
Efforts :
<select name="efforts" id= "efforts_select" onchange="checkChange()">
<option value=""> -Select- </option>
<?php
$result = $db_link->query("SELECT * FROM efforts_lookup ");
while($row= $result->fetch_row()) {
$id = $row[0];
$value = $row[1];
echo "<option value='$id'>$value</option>";
}
?>
</select>
<br/>
<br/>
<p> <font color='red'> * </font> Client Name:
<select name="client_name" id= "client_name_select" onchange="checkChange()">
<option value=""> -Select- </option>
<?php
$result = $db_link->query("SELECT * FROM Clients_Lookup");
while($row= $result->fetch_row()) {
$id = $row[0];
$value = $row[1];
echo "<option value='$id'>$value</option>";
}
?>
</select>
</p>
<br/>
<p> <font color='red'> * </font> Project Name:
<select name="project_name" id= "project_name_select" onchange="checkChange()">
<option value=""> -Select- </option>
<?php
$result = $db_link->query("SELECT * FROM clients_projects_lookup");
while($row= $result->fetch_row()) {
$id = $row[1];
$value = $row[2];
echo "<option value='$id'>$value</option>";
}
?>
</select>
</p>
<br/>
<font color='red'>*</font>
System/Device : <input type="text" name="system_and_device" id="system_and_device_textarea" oninput="checkChange()"/><br />
<br/>
<font color='red'>*</font>
Finding : <br/>
<textarea name="finding" cols="100" rows="10" id="finding_textarea" oninput="checkChange()"></textarea>
<br/>
<br/>
<font color='red'>*</font>
Implication: <br/>
<textarea name="implication" cols="100" rows="10" id="implication_textarea" oninput="checkChange()"></textarea>
<br/>
<br/>
<font color='red'>*</font>
Recommendation : <br/>
<textarea name="recommendation" cols="100" rows="10" id="recommendation_textarea" oninput="checkChange()"></textarea>
<br/>
<br/>
<input type="button" value="Back" onclick="history.go(-1);return true" />
<input type="submit" value=" Save " disabled="true" id= "save_button" />
<br/>
<br/>
<p> NOTE: <font color='red'> * </font>indicates a required field</p>
</fieldset>
</form>
</div>
函数checkChange()
{
var title_txt=document.getElementById('title_textarea').value.replace(/^\s+\s+$/g,“”);
var system_and_device_txt=document.getElementById('system_and_device_textarea').value.replace(/^\s+\s+$/g,“”);
var finding_txt=document.getElementById('finding_textarea').value.replace(/^\s+|\s+$/g,“);
var implication_txt=document.getElementById('implication_textarea').value.replace(/^\s+|\s+$/g,“);
var recommendation_txt=document.getElementById('recommendation_textarea').value.replace(/^\s+\s+$/g,“”);
if(document.getElementById('service\u name\u select')。selectedIndex!=“0”&&
document.getElementById('risk_rating_select')。selectedIndex!=“0”&&
document.getElementById('root\u cause\u select')。selectedIndex!=“0”&&
document.getElementById('impact_select')。selectedIndex!=“0”&&
document.getElementById('likelization_select')。selectedIndex!=“0”&&
document.getElementById('U select')。selectedIndex!=“0”&&
document.getElementById('client\u name\u select')。selectedIndex!=“0”&&
document.getElementById('project\u name\u select')。selectedIndex!=“0”&&
标题\u txt!“”&&
系统和设备&&
查找_txt!“”&&
含义_txt!=“”&&
建议_txt!“”
)
document.getElementById('save_按钮')。disabled=false;
其他的
document.getElementById('save_按钮')。disabled=true;
}
插入新数据
*服务名称:
-选择-
window.onload=function(){
var someparm=;//假设一个数字,如果不使用引号
支票兑换(someparm);
}
功能检查更改(parm){
document.getElementById('save_按钮')。disabled=(parm==0)?true:document.getElementById('service_name_select')。selectedIndex<1||
document.getElementById('risk_rating_select')。selectedIndex<1||
document.getElementById('root\u cause\u select')。selectedIndex<1||
document.getElementById('impact_select')。selectedIndex<1||
document.getElementById('likelization_select')。selectedIndex<1||
document.getElementById('efforcess_select')。selectedIndex<1||
document.getElementById('client_name_select')。selectedIndex<1||
document.getElementById('project\u name\u select')。selectedIndex<1||
title_txt==“”||
系统和设备||
查找_txt==“”||
含义\u txt==“”||
建议_txt==“”;
}
window.onload=function(){
var someparm=;//假设一个数字,如果不使用引号
支票兑换(someparm);
}
功能检查更改(parm){
document.getElementById('save_按钮')。disabled=(parm==0)?true:document.getElementById('service_name_select')。selectedIndex<1||
document.getElementById('risk_rating_select')。selectedIndex<1||
document.getElementById('root\u cause\u select')。selectedIndex<1||
document.getElementById('impact_select')。selectedIndex<1||
document.getElementById('likelization_select')。selectedIndex<1||
document.getElementById('efforcess_select')。selectedIndex<1||
document.getElementById('client_name_select')。selectedIndex<1||
document.getElementById('project\u name\u select')。selectedIndex<1||
title_txt==“”||
系统和设备||
查找_txt==“”||
含义\u txt==“”||
建议_txt==“”;
}
添加任一事件
添加任一事件
正如我已经发布的。将事件处理程序内联是不可取的做法。谢谢。在另一个页面中,我需要执行相同的操作,但函数接受一个参数。我还能用同样的方法吗?@travelingsalesman如果我明白你的意思,只要你能从某个地方得到参数,为什么不呢。@mplungjan抱歉,但当我发布它时,它没有给我任何其他答案。当然,你是对的,这不是一个好的做法,但你看到它的使用。很高兴知道你会遇到什么。正如我已经发布的。将事件处理程序内联是不可取的做法。谢谢。在另一个页面中,我需要执行相同的操作,但函数接受一个参数。我还能用同样的方法吗?@travelingsalesman如果我明白你的意思,只要你能从某个地方得到参数,为什么不呢。@mplungjan抱歉,但当我发布它时,它没有给我任何其他答案。当然,你是对的,这不是一个好的做法,但你看到它的使用。不过,很高兴知道您会遇到什么。关于“带参数”,我想做的是:请参阅更新,请不要使用body onload,而是使用我建议的构造。你也需要一个;在echo$size之后代码>完美!非常感谢你的帮助。我想在这里再添加一件事,即在编写windows.onload之前,必须定义示例中的变量someparm。这就是我如何使它工作的。我不知道你以前所说的定义是什么意思。如果愿意,也可以使用checkChange()。但是我相信你必须在结束前的语句后面加一个分号?>是的,对不起,我错过了那个分号
<script>
window.onload=function() {
var someparm = <?php echo $size; ?>; // assuming a number, if not use quotes
checkChange(someparm);
}
function checkChange(parm) {
document.getElementById('save_button').disabled = (parm==0) ? true : document.getElementById('service_name_select').selectedIndex < 1 ||
document.getElementById('risk_rating_select').selectedIndex < 1 ||
document.getElementById('root_cause_select').selectedIndex < 1 ||
document.getElementById('impact_select').selectedIndex < 1 ||
document.getElementById('likelihood_select').selectedIndex < 1 ||
document.getElementById('efforts_select').selectedIndex < 1 ||
document.getElementById('client_name_select').selectedIndex < 1 ||
document.getElementById('project_name_select').selectedIndex < 1 ||
title_txt == "" ||
system_and_device_txt == "" ||
finding_txt == "" ||
implication_txt == "" ||
recommendation_txt == "";
}
</script>
<body onload="checkChange();">
window.onload=function(){
checkChange();
}