2013-08-04 68 views
0

嗯,我正在一個網站上工作,在那裏我想在提交時清除註冊表單。提交表單被重定向到一個php腳本,我通過php腳本發送表單到電子郵件。我不知道我在哪裏出錯,但我無法在提交後清除表單的內容。它成功地檢查空白值,當我提交它不清除控制,我使用的功能清除表單,如果我之前運行提交..清除表單,但沒有數據發送到腳本..請幫助我同樣表格未提交已清除

這是我的Java scirpt

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> 

請讓我知道我錯了......我知道我是搞亂這個簡單事情。

+0

你有沒有試過在dif不同的瀏覽器?我記得firefox在表單自動完成時遇到了一個煩人的問題。 – amenadiel

+0

我想在Chrome和firefox.not兩個工作都一樣。 – Mangesh

回答

0

給了形式的行動,<form action="" ... >

+0

也試過,也沒有工作 – Mangesh

1

變化

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

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

,或者讓你已經擁有的功能:

function clearForm(form) { // pass a DOM element 
    form.reset(); 
} 
+0

的確實施了同樣的,但還是不行。我能夠收到電子郵件。但表格沒有被清除 – Mangesh