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
chaitanya90
7072 gold badges8 silver badges25 bronze badges
3 Answers 3
I think you're missing the $ in front of the ('#form') selector...
Sign up to request clarification or add additional context in comments.
Comments
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
Jozef Dúc
9632 gold badges18 silver badges29 bronze badges
Comments
u forgot something :
('#form').submit(); // This doesn't
try to add $.
answered Aug 19, 2014 at 8:03
NomNomNom
8913 gold badges13 silver badges37 bronze badges
Comments
default
$('#form').submit();, you forgot$