0

我不确定添加按钮是否是造成问题的原因,因为它可以在其他浏览器上完美运行。我希望你能以某种方式帮助我。谢谢你。顺便说一下,这是完整的 .php 代码。

<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>
4

2 回答 2

0

你可以不放入javascript:属性onclickon带前缀的属性是回调(有效的 JS 函数)。javascript:类似于协议规范。所以你javascript:只能在href属性中使用。就像是:

<a href="javascript: alert(123)">test</a>

要解决您的问题,只需javascript:onlick.

<div id="addBtn">   
        <a href="#" onclick="validateForm(action);return false;"><img src="images/add.png" height="27" width="60"></a>
</div>   
于 2012-07-16T08:33:27.747 回答
0

这段代码有问题:

<a href="#" onclick="javascript: validateForm(action);return false;">

它应该写成:

<a href="#" onclick="validateForm(document.forms['userLocation'].action);return false;">

将您的验证器指向表单的操作。

于 2012-07-16T10:24:38.210 回答