PDA

View Full Version : Opening a new window from a form submit



alip73
06-26-2008, 01:44 PM
Hello, I have a form in which I have set up a preview page that appears in a new window in which the user can browse their content. I have that working fine however my regular submit button now directs to this preview pop up page which i certainly don't want to happen.



<head>
<script>
function cForm(form)
win=window.open('','myWin','toolbars=0');
form.target='myWin';
form.action='prev_event.php'
}
</script>
</head>





<INPUT type="submit" name="action" value="Publish Article">
<input name="buttonB" type="submit" value="Preview" onclick="cForm(this.form)">


Any suggestions anybody.

Thanks

Nile
06-26-2008, 01:50 PM
You don't want to have it on the submit button. In your forum tag:


<form>

Add this:


<form onsubmit="cForm(this)">

I took off this.form, and made it this because it's on the form.

jscheuer1
06-26-2008, 01:54 PM
For the events of form elements, this.form is perfectly good.

The problem here is that you have two submit buttons.

If only one is required, only one should be used, the other can be an ordinary button that does something.

You might consider two forms, each with their own submit button. The data in the second form could be copied and/or cloned from the first and be largely or totally unseen by the user.

Nile
06-26-2008, 02:07 PM
An ordinary button as I recall is this:


<button>Hello</button>

If he uses this then it will act as a submit button to as I remembered when I did that.
So he'd need to use an input type="button:


<input type="button" value="Hello">

Correct me if I'm wrong, please.

jscheuer1
06-26-2008, 02:28 PM
If the form has a submit button, other buttons should not submit it. Generally the button tag should not be used, as everything you can do with it can be done with the more standard input tag with its type set as 'button'.

Here is an example of what (using two forms) I am talking about (tested in FF only):


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>
<body>
<form action="#">
<div>
<input type="text" name="bob" value="something"><br>
<textarea name="sid" cols="50" rows="5">Hi There Folks!</textarea><br>
<input type="submit" value="s1">
</div>
</form>
<form action="#" target="_blank" onsubmit="for (var els1 = document.forms[0].elements, i = els1.length - 1; i > -1; --i)
if(els1[i].value && els1[i].name && this.elements[els1[i].name])
this.elements[els1[i].name].value = els1[i].value;
return true;">
<div>
<input type="hidden" name="bob"><input type="hidden" name="sid">
<input type="submit" value="s2">
</div>
</form>
</body>
</html>