Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can a submit button open multiple windows?

Posted on 2010-08-20
11
Medium Priority
?
423 Views
Last Modified: 2012-08-13
I have a form in a php doc that opens
<form target="_blank" method="POST" action="voucher_verify.php?id=3">
...  input fields ....
<input name="voucher_submit" type="submit" value="Print Voucher">
</form>

Upon clicking submit, the form opens a new window that inserts the information into a sql db, and creates a form to be printed.
However, the page where the submit button resides stays open.

I want to to work so that when you click submit, it opens the new window the way it does now, but also redirect the current page back to anything else ... (i.e. index.php)
I tried some java, which is probably the best method - I'm just doing it wrong.

I tried something along the lines of <input name="voucher_submit" type="submit" onclick="index.php" value="Print Voucher">

Please help
0
Comment
Question by:Imaginx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 1

Author Comment

by:Imaginx
ID: 33486129
I may not have been completely clear. My title says "Can a submit button open multiple windows"

I don't want to open multiple windows. I want to open a new window & redirect the page on the current window.

-S
0
 
LVL 2

Expert Comment

by:j_coreil
ID: 33486299
Yes, very easily.
<html>
<body>

<script type="text/javascript">
w=window.open();
w.document.open();
w.document.write("<h1>Hello World!</h1>");
w.document.close();

window.location="http://www.yahoo.com/";

</script>

</body>
</html>

Open in new window

0
 
LVL 2

Expert Comment

by:j_coreil
ID: 33486311
All you need to do is add the javascript to the submit button as the action.
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 31

Accepted Solution

by:
Marco Gasi earned 2000 total points
ID: 33487069
All you need is to correct your code this way:

 <input name="voucher_submit" type="submit" onclick="location.replace('index.php');" value="Print Voucher">

Best regards
0
 
LVL 1

Author Comment

by:Imaginx
ID: 33487775
Here is the actual line pulled straight out of the php file.


It is properly opening the new window, but not replacing the current one... Can you see what I have wrong here ??
<?php
echo "<form name=\"voucher_print\" target=\"_BLANK\" method=\"POST\" action=\"intake_print.php?id=2\">";				
echo "<input type=\"hidden\" name=\"first_name\" value=\"$first_name\">";
echo "<input type=\"hidden\" name=\"last_name\" value=\"$last_name\">";
echo "<p><center>If the above information is correct, click print. Otherwise, click Back and correct the information.";
echo "<p><center><input type=button value=\"Back\" onClick=\"history.go(-1)\">";
echo "&nbsp&nbsp<input type=\"submit\" onclick=\"location.replace('index.php');\" name=\"submit_a\" value=\"Print Voucher\"><form><p>";
?>

Open in new window

0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 33487857
The only error I can see is tha missing end tag for form in line seven: you write <form> instead then </form>
0
 
LVL 1

Author Comment

by:Imaginx
ID: 33487875
Good call, but that shouldn't stop the java from redirecting ... No ??
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 33488001
Yes, I only said that was the only error I saw... You could use firebug (if you use firefox) to see errors. My test code works fine:

<?php
echo "<form target=\"_blank\" action=\"realwriting.php\" method=\"post\">";
echo "<input type=\"submit\" id=\"submit\" name=\"submit\" onclick=\"location.replace('temptemp.php');\" value=\"Submit\" />";
echo "</form>";
?>

This open a new tab in firefox and change the actual tab to temptemp.php :-(
0
 
LVL 1

Author Comment

by:Imaginx
ID: 33488232
All the employees that use this app are using IE.
I work on a Mac, and use Safari.

The java worked for me on my Mac using Firefox, and even on my Mac when I run IE in Parallels .... Just doesn't work with Safari ... ??

Either way, it achieves what I need - Thanks !!
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 33488274
Glad problem is solved. Only for your information, I've tested with Safari for Windows and it works also. So it seems Mac prevent for some reason this script to work! Good work.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 33488334
I intended: all the best for your work
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question