PDA

View Full Version : form - 2 buttons (normal-popup)


scsi
11-03-2003, 08:39 PM
hi there,
after a search on forum i hadn't find the solution for my task.
I have a form with 2 buttons, 1 for submitting the form, the other for previewing it.
i need a jscript that make open a popup window if preview button is clicked, and normal one if submit is clicked...

<form name="form" method="post" action="">
<input type="submit" name="submit" value="submit">
<input type="submit" name="preview" value="preview">
</form>

thanks for help

COBOLdinosaur
11-03-2003, 10:03 PM
<form name="form" method="post" action="submitscript.cgi">
<input type="submit" name="submit" value="submit">
<input type="button" name="preview" value="preview"
onClick="functionforpopup()">
</form>

scsi
11-04-2003, 11:57 AM
well i made a step ahead.
now form have 2 buttons, one for show preview, the second to directly insert data without preview.
What I miss now is how to have the preview page opened in a popup(with size,bars etc customized) instead of simple blank page.
thanks in advance for helping

<script language=javascript>

function preview()
{
document.input.action = "preview.php"
document.input.target = "_blank"; // Open in a new window
document.input.submit(); // Submit the page
return true;
}

function insert()
{
document.input.action = "insert_write.php"
//document.input.target = "_blank"; // Open in a new window
document.input.submit(); // Submit the page
return true;
}

</script>

<form name='input' action='' method='POST'>
<textarea name='titolo' cols='30' rows='2' class='form'></textarea>
<INPUT type="button" value="A" name=A onclick="return preview();">
<INPUT type="button" value="B" name=B onclick="return insert();">
<input type=reset value="Clear form" name="reset">
</p></form>

COBOLdinosaur
11-04-2003, 05:47 PM
Well you can't open a popup like that off of a form action. You have to use the window.open() method, and set the options. The url will have to include all the arguments that would normally be passed by the form, so you will have to build the argument string off of the form values and then append it to the url like: preview.php?titolo=somevalue&A=A...etc

The data could contain anything, so you will probably have to pre-build url string and escape it; an it could still get screwup. All in all, it is not a good idea to do something like this as it will probably fail as often as it works. What is it that you are trying to preview, that the user cannot just see by doing a straight query?

Cd&

scsi
11-04-2003, 08:33 PM
hi Cobol* and thanks for your replys

What is it that you are trying to preview, that the user cannot just see by doing a straight query?

nothing secret... just would users can preview their form in a separate window.
preview windows won't allow modify, will be just a reference.
i will try to call preview.php as you suggested.

thanks again by now

adios
11-04-2003, 09:15 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">

var prevWin = null;

function open_prevWin(oForm)
{
if (prevWin && !prevWin.closed)
prevWin.close();
oForm.action = 'preview.php';
prevWin = window.open('about:blank', 'prevWin', 'left=200,top=200,width=500,height=400,status=0'); //remove spaces above! (courtesy of this board)
if (prevWin && !prevWin.closed)
prevWin.focus();
return true;
}

function insert_submit(oForm)
{
oForm.action = 'insert_write.php';
oForm.target = '_self';
return true;
}

</script>
</head>
<body>
<form name="input" action="insert_write.php" method="POST" target="prevWin">
<textarea name="titolo" cols="30" rows="2" class="form"></textarea>
<INPUT type="submit" value="preview" name="A" onclick="return open_prevWin(this.form)">
<INPUT type="submit" value="insert" name="B" onclick="return insert_submit(this.form)">
<input type=reset value="Clear form" name="reset">
</p>
</form>
</body>
</html>

scsi
11-06-2003, 04:29 PM
hi adios and thank.
it does the job but the redirection that happen when opening popup seems not completly proof.
infact when opening popup first is called a blank page then will be redirected to preview.php.
if will be possible solve this strange behaviour script will fit exactly with the one i needed.
thanks again

adios
11-06-2003, 04:51 PM
Hmm...not sure what you mean. The blank 'dummy' page loaded initially in the pop-up? Something has to go in there first, since the form isn't targeted until it's submitted, a second later. You can replace the 'about:blank' (blank page) with anything else; even a local 'dummy' document like so:

prevWin = window.open('javascript:opener.dummyPage()', 'prevWin', 'left=200......

...and

function dummyPage()
{
return '<body bgcolor=black text=white><h2>Loading.....</h2></body>';
}

Hope that helps...

scsi
11-06-2003, 05:04 PM
yes that helped!
it works better now :thumbsup:

thanky