I have a jsp that contains an iframe and a button. The iframe contains a jqgrid. I need to alert the record count of jqgrid inside that iframe when the button is pressed.
I tried
var grid = jQuery("#myFrame").contents().find("#myGrid");
var count = grid.jqGrid('getGridParam', 'reccount');
alert(count); //alerts undefined
How can I access jqgrid from an iframe?
UPDATE:
HTML fragments
<body>
<iframe
frameborder="0" name="myFrame" id="myFrame" width="100%"
height="290px" scrolling="no"
src="myFrameContent.jsp">
</iframe>
<form action="frameAction" method="post" target="myFrame">
<button>refresh table</button>
</form>
</body>
When the button is pressed the form will be submitted then the iframe will be reloaded with the json string (response) as the jqgrid's data. as per Olga's answer I tried putting
$(function(){
$("#myFrame").load(function(){
var grid = $("#myFrame").contents().find("#myGrid");
var count = grid.jqGrid('getGridParam', 'reccount');
alert("count=" + count);
});
});
in the parent jsp, it still alerts undefined. what am I missing?