2016-12-02 25 views
2
<form method="post" name="frm_no_kids" class="getstarted" action="step1.php"> 
    <input type="hidden" id="price_value" name="fee" value="<?php echo encrypt(499); ?>"> 
    <input type="hidden" id="divorce_type" name="divorce_type" value="no_kids"> 
    <a class="btn border-btn yellow-btn started-hover" title="Get Started" href="javascript:frm_no_kids.submit();">Get Started </a> 
</form> 

我有這個鏈接,它不工作。這給了我錯誤。提交不是在javascript中工作

TypeError: frm_no_kids.submit is not a function

+0

不要使用內聯事件那樣,這是不好的做法。使用外部事件處理程序 –

+0

但現在,只要給我一個解決這個錯誤的方法。 – neha910

+0

@ neha910你應該積極採納建議。 – Tiger

回答

2

我在表單中添加了一個ID,並呼籲錨標記點擊一個函數來提交表單數據:

<form method="post" name="frm_no_kids" id="frm_no_kids" class="getstarted" action="step1.php"> 
     <input type="hidden" id="price_value" name="fee" value="<?php echo encrypt(499); ?>"> 
     <input type="hidden" id="divorce_type" name="divorce_type" value="no_kids"> 
     <a class="btn border-btn yellow-btn started-hover" title="Get Started" href="javascript:;" onclick="submitData()">Get Started </a> 
</form> 
<script> 
     function submitData(){ 
      document.getElementById("frm_no_kids").submit(); 
     } 
</script> 
+0

是的,非常感謝,不是它工作正常。 Thanx再一次:) @Ravi – neha910

+0

你最歡迎!感謝upvote –

0
document.getElementsByName('frm_no_kids')[0].submit(); 

檢查這有助於

<form method="post" name="frm_no_kids" class="getstarted" action="step1.php"> 
        <input type="hidden" id="price_value" name="fee" value="<?php echo encrypt(499); ?>"> 
        <input type="hidden" id="divorce_type" name="divorce_type" value="no_kids"> 
        <a class="btn border-btn yellow-btn started-hover" title="Get Started" href="javascript:document.getElementsByName('frm_no_kids')[0].submit();">Get Started </a> 
        </form> 
0

它在表單中使用實際的提交按鈕而不是像提交按鈕那樣的超鏈接會更有意義。如果您想更多地控制顯示/格式,可以使用<input type="submit"><button type="submit">

如果您在使用非提交按鈕(如超鏈接)設置,那麼這將是最好給表單自身的ID:

<form method="post" id="frm_no_kids" name="frm_no_kids" class="getstarted" action="step1.php"> 
    <input type="hidden" id="price_value" name="fee" value="<?php echo encrypt(499); ?>"> 
    <input type="hidden" id="divorce_type" name="divorce_type" value="no_kids"> 
    <a class="btn border-btn yellow-btn started-hover" title="Get Started" href="javascript:document.getElementById('frm_no_kids').submit();">Get Started </a> 
</form> 

正如在評論中提到的,使用事件偵聽器要好得多:

HTML:

<form method="post" id="frm_no_kids" name="frm_no_kids" class="getstarted" action="step1.php"> 
    <input type="hidden" id="price_value" name="fee" value="<?php echo encrypt(499); ?>"> 
    <input type="hidden" id="divorce_type" name="divorce_type" value="no_kids"> 
    <a id="frm_no_kids_submit" class="btn border-btn yellow-btn started-hover" title="Get Started" href="#">Get Started </a> 
</form> 

JS:

document.getElementById("frm_no_kids_submit").addEventListener("click", function(){ 
    document.getElementById("frm_no_kids").submit(); 
}); 
0

添加一個ID您從和使用該ID在你的JavaScript

<form method="post" name="frm_no_kids" id="frm_no_kids" class="getstarted" action="step1.php"> 
    <input type="hidden" id="price_value" name="fee" value="<?php echo encrypt(499); ?>"> 
    <input type="hidden" id="divorce_type" name="divorce_type" value="no_kids"> 
    <a class="btn border-btn yellow-btn started-hover" title="Get Started" href="javascript:;" onclick="submitData()">Get Started </a> 
</form> 
<script> 
    function submitData(){ 
     document.getElementById("frm_no_kids").submit(); 
    } 
</script>