Jquery form submit () call back not working

I have an iframe and form. The purpose of the form is iframe. When I submit the form, the results page should load in the iframe. I added the code below:

<html>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
 <script type="text/javascript">

 function submitForm() {
 $("form#testForm").submit(function(){
   alert('hii')
  });
}
</script>

</head>

<body>

<iframe name="testFrame" id="testFrame" frameborder="1" scrolling="no" width="500"     height="200"></iframe>
<form name="testForm" id="testForm" action="http://www.yahoo.com" target="testFrame">    </form>

<button name="testBtn" value="submit" onclick="submitForm();">submit</button>
</body>
</html>

The warning is not coming ... Help me please ...

+3
source share
1 answer

As docs tells you, if you call the jQuery event method with an argument, it adds an event handler rather than firing the event. You need to add an event handler beyond submitForm.

$(document).ready($("form#testForm").submit(function(){
   alert('hii')
});


function submitForm() {
    $("form#testForm").submit();
}
+9
source

Source: https://habr.com/ru/post/1739973/


All Articles