0

好吧,我在一个网站上工作,我想在提交时清除注册表。提交的表单被重定向到一个 php 脚本,我通过 php 脚本将表单发送到电子邮件。我不知道我哪里出错了,但是提交后我无法清除表单的内容。它成功检查了空白值,当我提交时它不会清除控件,我正在使用一个函数清除表单,如果我在提交之前运行它..它会清除表单但没有数据发送到脚本..请帮助我进入相同

这是我的 Java 脚本

function verifyEmail(form) {
    //alert(frmContact.email.value);
    checkEmail = contactform.email.value;
    form=contactform;   
    //alert("Please select an answer.");

    if(form.fname.value=='')

        {

            alert("Name is blank");

            form.fname.select();

            return false;

        }

    else if(form.dob.value=='')

        {

            alert("Date Of Birth is blank");

            form.dob.select();

            return false;

        }



        else if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.'))) 

    {

    alert("You have entered an invalid email address. Please try again.");

    form.email.select();

    return false;

    } 
        else if(form.mob.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1)

        {

            alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx");

            form.mob.select();

            return false;

        }
    else if(form.state.value=='')

        {

            alert("State is blank");

            form.state.select();

            return false;

        }

        else if(form.city.value=='')

        {

            alert("City is blank");

            form.city.select();

            return false;

        }


        else if(form.message.value=='')

        {

            alert("Message is blank");

            form.message.select();

            return false;

        }
    else

    {
    form.method="post";
form.target="_self";
form.action="reg_contact.php";
form.submit();
form.fname.value='';
form.dob.value='';
form.email.value='';
form.mob.value='';
form.state.value='';
form.city.value='';
form.message.value='';
clearForm();


    }
    }

    //--></script>
    <script language="javascript">
    function clearForm(form)
    {
        $(":input", form).each(function()
        {
        var type = this.type;
        var tag1= this.tagName.toLowerCase();
        var tag = this.tagName.toLowerCase();
            if (type == 'text' || tag=='textarea' )
            {
            this.value = "";
            }
        });
    };

这是我的表单内容

<form id="contactform" class="form" method="post" name="contactform" onsubmit="return(verifyEmail())" style="height: 499px">
    <fieldset>
    <div>
        <label for="fname" style="width: 216px">Full Name:<span> *</span>
        </label><input id="fname" name="fname" type="text"> </div>
    <div style="margin-left: 45%; margin-top: -13%;">
        <label for="name" style="width: 250px">Date Of Birth:<span> *</span></label><input id="datepicker" name="dob" type="text" />
    </div>
    <div>
        <label style="width: 216px">E-mail:<span>*</span></label><input id="email" name="email" type="text">
    </div>
    <!--
                            <div>
                                <label for="email" >Email: <span>*</span></label>
                                <input name="email" type="email" id="email" pattern="^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$" />
                            </div>
                    -->
    <div style="margin-left: 45%; margin-top: -13%;">
        <label accesskey="U" for="name" style="width: 216px">Mobile Number:<span> 
        *</span></label> <input id="mob" name="mob" type="text" /> </div>
    <div>
        <label>State:<span> *</span></label>
        <input id="state" name="state" type="text"> </div>
    <div style="margin-left: 45%; margin-top: -12.5%;">
        <label accesskey="U" for="name">City:<span> *</span></label>
        <input id="city" name="city" type="text"> </div>
    <div>
        <label accesskey="U" for="name">Country:<span> *</span></label>
        <input id="country" disabled="disabled" name="country" type="text" value="India" />
    </div>
    <div>
        <label>Course:<span> *</span></label>
        <select id="cource" name="cource" style="height: 34px; width: 241px">
        <option value="Diploma Polytechnic">Diploma - Polytechnic</option>
        <option selected="" value="UG-BE">Bachelor Of Engineering (BE)</option>
        <option value="UG-B.Tech">Bachelor Of Technology (B.Tech)</option>
        <option value="PG-MCA">Master Of Computer Application (MCA)</option>
        <option value="PG-ME">Master Of Engineering (ME)</option>
        <option value="PG-M.Tech">Master Of Technology (M.Tech)</option>
        </select> </div>
    <div>
        <label accesskey="C" for="comments">Message: <span>*</span></label>
        <textarea id="comments" cols="40" name="message" rows="3" spellcheck="true"></textarea>
    </div>
    </fieldset>
    <input id="submit" class="submit" style="height: 36px; width: 90px; margin-top: -0.18%;" type="submit" value="      Send      ">
    <input id="reset" class="reset" style="height: 36px; width: 90px; margin-left: 5px; margin-top: -0.18%;" type="reset" value="   Reset    ">
    <div class="clearfix">
    </div>
</form>

请让我知道我哪里出错了......我知道我在搞砸这个简单的事情。

4

2 回答 2

1

改变

<form ... onsubmit="return(verifyEmail())" ...>

<form ... onsubmit="this.reset(); return verifyEmail();" ...>

或保留您已有的功能:

function clearForm(form) { // pass a DOM element
    form.reset();
}
于 2013-08-04T17:35:30.210 回答
0

给形式一个动作,<form action="" ... >

于 2013-08-04T17:34:53.847 回答