View Full Version : New Window
esb01
06-05-2003, 06:25 PM
I've been trying to load a new page on a button click using the following code in my main.aspx
<FORM id="Form1" onclick="window.open('newwindow.aspx','win1','width=400,height=320')" target="_blank" method="post">
<INPUT id="btn1" type="submit" value="Button" name="btn1" runat="server">
</FORM>
This new page is loaded fine but also main.aspx is loaded again, so I have 3 windows opened. What did I do wrong?
arnyinc
06-05-2003, 08:29 PM
You are posting the form to a _blank page AND calling window.open with the onclick event.
<form>
<input type="button" value="click me" onclick="window.open('newwindow.aspx','win1','width=400,height=320')">
</form>
or
<form onsubmit="window.open('newwindow.aspx','win1','width=400,height=320')">
<input type="submit">
</form>
Since the onclick is in your <form> tag, you don't even have to click your button in order to trigger the onclick. You can click just above the button and it will still popup the newwindow.aspx.
esb01
06-06-2003, 12:11 AM
thanks, I've been using Web forms button not Html input control and I thought they behave differently at this point but no...
Thie following worked fine -
<FORM onclick="window.open('newwindow.aspx','win1','width=400,height=300')">
<INPUT id="btn1" type="submit" value="Button" name="btn1" runat="server">
</FORM>
arnyinc
06-06-2003, 04:27 PM
If you have the onclick event in your <form> tag, it will be triggered any time any one clicks in your form. Regardless if it is the button, a textarea, a text box, or just white space.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.