我不太確定添加按鈕是否對這個問題負責,因爲它完全在其他瀏覽器上工作。無論如何,我希望你能幫助我。謝謝。順便說一下,這裏是完整的.php代碼。(PHP&JavaScript)href添加按鈕在Mozilla上不起作用,但適用於IE和Google
<html>
<head>
<LINK REL=StyleSheet HREF="addOfficerStyle.css" TYPE="text/css" MEDIA=screen>
<script type="text/javascript">
function validateForm(action)
{
var lname=document.forms["validation"] ["lname"].value;
var fname=document.forms["validation"] ["fname"].value;
var mname=document.forms["validation"] ["mname"].value;
var address=document.forms["validation"] ["address"].value;
var contact=document.forms["validation"] ["contact"].value;
if (lname==null || lname=="" || fname==null || fname=="" || mname==null || mname=="" || address==null || address=="" || contact==null || contact=="")
{
alert("Fill all required fields");
return false;
}
else{
form = document.getElementById('userLocation');
form.action = action;
form.submit();
}
}
function numeric(e)
{
var unicode=e.charCode ? e.charCode : e.keyCode;
if (unicode==8 || unicode==9 || (unicode >=48 && unicode <=57))
{
return true;
}
else
{
return false;
}
}
function inputLimiter(e,allow)
{
var AllowableCharacters = '';
if (allow == 'Letters'){AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';}
var k = document.all?parseInt(e.keyCode): parseInt(e.which);
if (k!=13 && k!=8 && k!=0)
{
if ((e.ctrlKey==false) && (e.altKey==false))
{
return (AllowableCharacters.indexOf(String.fromCharCode(k))!=-1);
}
else
{
return true;
}
}
else
{
return true;
}
}
</script>
</head>
<body onunload="opener.location=('PromoOfficer.php')">
<br><br>
<form id="userLocation" name="validation" method="post" onsubmit="return validateForm()">
<div id="tableAlign">
<table>
<tr>
<td><b>ADD: Promo Officer</td></b>
</tr>
<tr>
<td>Last name:</td> <td><input type="text" name="lname" maxlength="20" onkeypress="return inputLimiter(event,'Letters')" /></td>
</tr>
<tr>
<td>First name:</td> <td><input type="text" name="fname" maxlength="20" onkeypress="return inputLimiter(event,'Letters')" /></td>
</tr>
<tr>
<td>Middle name:</td> <td><input type="text" name="mname" maxlength="20" onkeypress="return inputLimiter(event,'Letters')" /></td>
</tr>
<tr>
<td>Address:</td> <td><input type="text" name="address" maxlength="50" /></td>
</tr>
<tr>
<td>Contact:</td> <td><input type="text" name="contact" maxlength="11" onkeypress="return numeric(event);" /></td>
</tr>
<tr>
<td>User Type:</td> <td><input type name = "usertype" readonly = "true" value = "Promo Officer"></td>
</tr>
</table>
</div>
<div id="addBtn">
<a href="#" onclick="javascript: validateForm(action);return false;"><img src="images/add.png" height="27" width="60"></a>
</div>
<!-- PHP -->
<?
include('global.php');
if(isset($_REQUEST['salesID']))
$pID = $_REQUEST['salesID'];
else
$pID = "";
if(isset($_REQUEST['lname']))
$lname = $_REQUEST['lname'];
else
$lname = "";
if(isset($_REQUEST['fname']))
$fname = $_REQUEST['fname'];
if(isset($_REQUEST['mname']))
$mname = $_REQUEST['mname'];
if(isset($_REQUEST['address']))
$address = $_REQUEST['address'];
if(isset($_REQUEST['contact']))
$contact = $_REQUEST['contact'];
if(isset($_REQUEST['usertype']))
$usertype = $_REQUEST['usertype'];
if($_POST)
{
$query = "INSERT INTO promoofficerform SET ";
$query = $query."LastName='".$lname."', ";
$query = $query."FirstName='".$fname."', ";
$query = $query."MiddleName='".$mname."', ";
$query = $query."Address='".$address."', ";
$query = $query."Contact='".$contact."', ";
$query = $query."UserType='".$usertype."' ";
//$query = $query."WHERE PromoNameID='".$pID."'";
//echo $query;
ExecuteQuery($query);
echo "<script type=\"text/javascript\">
<!--
window.close();
//-->
</script>";
}
?>
<!-- EndOfPHP -->
</form>
</body>
</html>
上面的代碼被運輸到jsfiddle ...看到它在這裏:http://jsfiddle.net/mDnpq/ – 2012-07-16 08:44:32
當在FF中運行時,JS錯誤說「opener爲空」,在onload甚至在你的身體標記。點擊提交按鈕時的另一個JS錯誤是「action is not defined」...在這裏你的表單中使用了'function validateForm(action)' – 2012-07-16 08:53:47