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>

I have this link and it is not working. This give me error like.

TypeError: frm_no_kids.submit is not a function

4
  • Don't use inline events like that, it's bad practice. Use an external event handler Commented Dec 2, 2016 at 6:39
  • But for now, just give me a solution for this error. Commented Dec 2, 2016 at 6:40
  • @neha910 You should take the suggestion positively. Commented Dec 2, 2016 at 6:43
  • @Tiger, Yes definately but that time i was in hurry, and thanks for the comment. Commented Dec 2, 2016 at 7:06

4 Answers 4

2

I added an id in your form and called a function on anchor tag click to submit your form data :

 <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>
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, Thanks alot, not it is working fine. Thanx once again :) @Ravi
0
   document.getElementsByName('frm_no_kids')[0].submit();

Check if this helps

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

Comments

0

It would make more sense to use an actual submit button in the form instead of a hyperlink that acts like a submit button. You can use <input type="submit"> or <button type="submit"> if you want more control over display/formatting.

If you are set on using a non-submit button (like your hyperlink), then it would be best to give the form its own 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>

As was mentioned in the comments, using an event listener is MUCH better:

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();
});

Comments

0

Add an ID to your From and use that ID in your 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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.