0

I have the following code for which submit() function just don't work. I know i am missing something very simple but i am unable to figure it out.

HTML

 <form id="form" method="post" action="/url/">
 <input type="hidden" name="hidden" value="hidden">
 </form>
 <span id="diagnose"><i class="fa fa-chevron-right"></i></span>
 <script type="text/javascript">
 $(document).diagnose();
 </script>

Jquery

(function( $ ){
$.fn.diagnose = function(){
 $("#diagnose").click(function(){
 //window.location.href = "/url"; //This works
 ('#form').submit(); // This doesn't
 });
};
}( jQuery ));
asked Aug 19, 2014 at 7:56
3
  • 1
    Should be $('#form').submit();, you forgot $ Commented Aug 19, 2014 at 7:59
  • ohh yess!! i knew this would be something this silly. Commented Aug 19, 2014 at 8:00
  • how did i miss that. Commented Aug 19, 2014 at 8:01

3 Answers 3

2

I think you're missing the $ in front of the ('#form') selector...

answered Aug 19, 2014 at 8:00
Sign up to request clarification or add additional context in comments.

Comments

1

There are two options

  • remove # and add document.getElementById('form').submit(); for pure javascript
  • add $ $('#form').submit(); for jQuery
answered Aug 19, 2014 at 7:59

Comments

1

u forgot something :

('#form').submit(); // This doesn't

try to add $.

answered Aug 19, 2014 at 8:03

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.