kosmas
asked on
How to force a new pop-up window when 'Submit' button is clicked
Hello to everyone,
I have a php/html form script where the user enters some details and a result is returned. Here's part of the form used:
<form id="form1" name="form1" method="post" action="">
<p>Encrypted Password:
<input name="encrypted" maxlength="128" size="50" type="text" id="encrypted" />
<input name="dec" type="submit" id="dec" value="Submit" />
What I want to do is when the user presses the 'Submit' button, I'd like a new window to pop up, that will load a specific URL I will provide.
Any help is much appreciated.
Thank you.
I have a php/html form script where the user enters some details and a result is returned. Here's part of the form used:
<form id="form1" name="form1" method="post" action="">
<p>Encrypted Password:
<input name="encrypted" maxlength="128" size="50" type="text" id="encrypted" />
<input name="dec" type="submit" id="dec" value="Submit" />
What I want to do is when the user presses the 'Submit' button, I'd like a new window to pop up, that will load a specific URL I will provide.
Any help is much appreciated.
Thank you.
Try this:
<form method=post target=_self>
<input type=submit value=Submit onClick="return openWindow('$url',500,300) ;">
</form>
<form method=post target=_self>
<input type=submit value=Submit onClick="return openWindow('$url',500,300)
</form>
ASKER
Xterm, would you be kind enough to actually inset your suggested code into the one I have already pasted? The code you suggest, should not modify the functionality of the existing form.
Many thanks
Many thanks
Absolutely, and glad you posted back, because I forgot to include the javascript that you'll need for that function to work. Here you go:
<html>
<head>
<script language=JavaScript>
function openWindow(url,width,height) {
popupWin = window.open(url, 'remote', 'scrollbars=0, resizable=0,width='+width+',height='+height);
return false;
}
</script>
</head>
<form id="form1" name="form1" method="post" action="">
<p>Encrypted Password:
<input name="encrypted" maxlength="128" size="50" type="text" id="encrypted" />
<input name="dec" type="submit" id="dec" value="Submit" onClick="return openWindow('http://www.someurl.com',500,300);"/>
</form>
</html>
"not change functionality"
your code will stop submission and not work in case of popup blockers
kosmas: is the popup unrelated to the form result?
your code will stop submission and not work in case of popup blockers
kosmas: is the popup unrelated to the form result?
I suggest you return the following from the form submission
<script type="text/javascript">
window.onload=function() {
var w = window.open("somepage.html ","_blank" ,"width=40 0,height=4 00");
if (!w) alert('Sorry, you have blocked popups')
}
</script>
Alternatively ajax the form result and show the popup in that part of the script
<script type="text/javascript">
window.onload=function() {
var w = window.open("somepage.html
if (!w) alert('Sorry, you have blocked popups')
}
</script>
Alternatively ajax the form result and show the popup in that part of the script
ASKER
To make this clear for everyone, here is the full code of the page. I'd like when someone presses the 'submit' button, the script to continue as it does now, but also pop up an additional window with a URL that I will provide.
You can use the code below and post it with your recommended changes.
Many thanks everyone!
<form id="form1" name="form1" method="post" action="">
<p>Encrypted Password:
<input name="encrypted" maxlength="128" size="50" type="text" id="encrypted" />
<input name="dec" type="submit" id="dec" value="Submit" />
<br/>
<br/>
Password:
<input name="decrypted" type="text" size="50" id="decrypted" value="
<?php
$Regex = "/^[A-z0-9]+$/";
if(isset($_POST['encrypted '])) {
if(!strlen($_POST['encrypt ed'])) {
echo "Input was empty";
return;
}
if(preg_match_all($Regex, $_POST['encrypted'], $Matches)) {
$command = "./decrypt.pl ".$_POST['encrypted'];
htmlspecialchars(system($c ommand));
} else {
echo "Invalid input";
return;
}
}
?>
"/>
<br>
You can use the code below and post it with your recommended changes.
Many thanks everyone!
<form id="form1" name="form1" method="post" action="">
<p>Encrypted Password:
<input name="encrypted" maxlength="128" size="50" type="text" id="encrypted" />
<input name="dec" type="submit" id="dec" value="Submit" />
<br/>
<br/>
Password:
<input name="decrypted" type="text" size="50" id="decrypted" value="
<?php
$Regex = "/^[A-z0-9]+$/";
if(isset($_POST['encrypted
if(!strlen($_POST['encrypt
echo "Input was empty";
return;
}
if(preg_match_all($Regex, $_POST['encrypted'], $Matches)) {
$command = "./decrypt.pl ".$_POST['encrypted'];
htmlspecialchars(system($c
} else {
echo "Invalid input";
return;
}
}
?>
"/>
<br>
<form id="form1" name="form1" method="post" action="">
<p>Encrypted Password:
<input name="encrypted" maxlength="128" size="50" type="text" id="encrypted" />
<input name="dec" type="submit" id="dec" value="Submit" />
<br/>
<br/>
Password:
<input name="decrypted" type="text" size="50" id="decrypted" value="
<?php
$ok = false;
$Regex = "/^[A-z0-9]+$/";
if(isset($_POST['encrypted'])) {
if(!strlen($_POST['encrypted'])) {
echo "Input was empty";
return;
}
if(preg_match_all($Regex, $_POST['encrypted'], $Matches)) {
$command = "./decrypt.pl ".$_POST['encrypted'];
htmlspecialchars(system($command));
$ok=true;
} else {
echo "Invalid input";
return;
}
}
if ($ok) {?>
<script type="text/javascript">
window.onload=function() {
var w = window.open("somepage.html","_blank","width=400,height=400");
if (!w) alert('Sorry, you have blocked popups')
}
</script>
<?php
}
?>
"/>
<br>
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
target="_blank"
To the form tag