Hi every body I wrote my application with php and java script. My app has one button called “replay†when user clicks on, a new window will be opened and he will write message and then send it. My problem is: when I use onkeyup, onkeydown, onmouseout event handlers within the new window to call function, I have object expected error in line 1 char 1. Please help me any help will be so appreciated This is my full code: <html> <head> <title>Replaying Message</title> </head> <body> <script language="javascript" type="text/javascript"> var WinReplay; function CheckFieldLength() { var len = WinReplay.document.getElementById('msgid').value.length; if (len > 700) { WinReplay.document.getElementById('msgid').value = WinReplay.document.getElementById('msgid').value.substring(0,700); len = 700; } WinReplay.document.getElementById('charcount').innerHTML = len; WinReplay.document.getElementById('remaining').innerHTML = 700 - len; } function OpenWindow(mobileNo) { WinReplay = window.open('','mywindow','top=10,resizable=1, width=450px,height=450px,toolbar=0,resize=0,scrollbars=0,status=1'); WinReplay.document.write('<html><head><title>replaying msg</title></head>'); WinReplay.document.write('<body dir="rtl">'); WinReplay.document.write('<form action="http://***.***.*.***/****" method="GET">'); WinReplay.document.write('<table dir="rtl">'); WinReplay.document.write('<tr> <td>mobile no</td> <td> <input type="text" value="'+mobileNo+'" disabled > </td></tr>'); WinReplay.document.write('<tr><td colspan="2"> </td></tr>'); WinReplay.document.write('<tr><td valign="top">message</td>'); WinReplay.document.write('<td>'); WinReplay.document.write('<input type="text" style="height: 200px; width:250px;" id="msgid" name="msg" onkeyup="CheckFieldLength();" onkeydown="CheckFieldLength();" onmouseout="CheckFieldLength();" >'); WinReplay.document.write('</td></tr>'); WinReplay.document.write('<tr><td> counter:</td><td>'); WinReplay.document.write('<small> <span id="charcount" dir="rtl">0</span> | '); WinReplay.document.write('<span id="remaining" dir="rtl">700</span> </small>'); WinReplay.document.write('</td></tr>'); WinReplay.document.write('<tr><td colspan="2"> </td></tr>'); WinReplay.document.write('<tr><td colspan="2" align="center"> <input type="submit" value="send" > </td></tr>'); WinReplay.document.write('</table>'); WinReplay.document.write('</form>'); WinReplay.document.write("</body></html>"); } </script> <input type="button" value="Replay" name="replay" onclick="javascript:OpenWindow('123456');"> </body> </html> Code (markup):
Within the new window there is no function called CheckFieldLength. You need to call opener.CheckFieldLength. Of course this relies on the parent window not being closed. Alternatively include the function from a .js file within the new window. If you do this, the closing script tag must be written as '<\/script>'. You don't need to call the function for both keydown and keyup events. keyup is sufficient. You must call document.close() after writing to a new window or you will get a constant hourglass in FireFox. Debugging is a lot easier using FireFox and ideally its FireBug extension.