tags:

views:

170

answers:

1

I have an iframe and a form. Form's target is iframe. When I submit form, the result page should load in iframe. I have attached the code below:

<html>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"&gt;&lt;/script&gt;
 <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 alert is not coming....Help me please...

+1  A: 

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

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


function submitForm() {
    $("form#testForm").submit();
}
outis
Thnx outis...it is working now...:-)
Aneesh
one more thing...how can i get the content height of the loaded page ? $("#iframeName").contents().find("body").height() is not working...any idea ? it gives 0...:(
Aneesh
outis