Shoutbox

html form/javascript help - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: html form/javascript help (/showthread.php?tid=67637)

html form/javascript help by MeEtc on 10-24-2006 at 03:17 PM

I'm trying  to make a form submit to a new popup window opened with javascript, close after loading, and have the form page simply refresh.

Here's what I have so far:

code:
<form action='script.php' method='post' target='WindowName'
    onSubmit="func=window.open('', 'WindowName', 'height=100,width=100');
    setTimeout(window.location.reload(true), 2000)">
<!-- Form elements -->
<input type='submit' value='Submit'>
</form>

The window will open and the script will open there. But, the form will not refresh and I don't know how to close the new window after it loads. I need all of the JS to be inline, not have an external script.

can anyone help?
RE: html form/javascript help by rav0 on 10-25-2006 at 07:36 AM

Couldn't you just get rid of the popup and have the page submit to itself?

To close the popup, in the popup page, window.close.

I don't know why the refresh doesn't work, but maybe it's because of no semicolon. You could also try document.location=document.location. Why do you need the timer?


RE: html form/javascript help by hmaster on 10-25-2006 at 10:09 AM

Make script.php with the script you want to execute when they press submit and add at the end window.close.

Your form should work like this:

code:
<form action='' method='post' onSubmit="window.open('script.php', 'WindowName', 'height=100,width=100'); setTimeout(window.location = unescape(window.location.pathname), 2000);return false;">
<!-- Form elements -->
<input type='submit' value='Submit'>
</form>
I think thats what you're trying to do?
RE: html form/javascript help by MeEtc on 10-25-2006 at 12:14 PM

quote:
Originally posted by rav0
Couldn't you just get rid of the popup and have the page submit to itself?
No, I don't have access to the script itself
quote:
Originally posted by rav0
Why do you need the timer?
to wait for the script to execute before refreshing, as it impacts the form page.
quote:
Originally posted by hmaster
Make script.php with the script you want to execute when they press submit and add at the end window.close.
I tried winFunc=window.open... and winFunc.document.onload=winFunc.close() combinaton, but get a security warning when trying to do it.

quote:
Originally posted by hmaster
Your form should work like this:
code:
<form action='' method='post' onSubmit="window.open('script.php', 'WindowName', 'height=100,width=100'); setTimeout(window.location = unescape(window.location.pathname), 2000);return false;">
<!-- Form elements -->
<input type='submit' value='Submit'>
</form>
I think thats what you're trying to do?
Will that actually submit the form info to script.php though?
RE: html form/javascript help by hmaster on 10-25-2006 at 07:40 PM

Oh right you wanted to carry it over to the popup which is easily done through GET methods.

code:
<form action='' method="post" onSubmit="window.open('script.php?submit=' + this.elements['submit'].value + '&name=' + this.elements['name'].value, 'WindowName', 'height=100,width=100'); setTimeout(window.location, 2000); return false;">
    <input type="text" name="name" /> <!-- just testing -->
    <input type="submit" name="submit" value="Submit" />
</form>
And I tested this in a file called script.php:
code:
<?php
$tf = (isset($_GET['submit'])) ? "True" : "False";
$name = (isset($_GET['name'])) ? $_GET['name'] : "False";

echo $tf;
echo "<br />";
echo $name;
?>
Which outputted:

    True
    Boo (this being what I put in the name input).
Only downside is that you have to put all of the names of the input boxes that you want to send over to script.php in the window.open() function.