Click to See Complete Forum and Search --> : refresh browser


yssirhc
05-05-2009, 11:16 AM
I have a cgi web page that displays some info and then has a form on the bottom for you to comment on that info.

The problem I'm having is that after the user submits a comment from that form, the browser displays a whole new web page. What I want it to do is refresh the page the user is on (the one with the form on it) and display some sort of message all on that same page. Either by having the message displayed somewhere on the form page itself or by having a popup window come up.

I've tried doing it with javascript:

<input type="submit" name="commentButton" value="Submit Comment" onclick="alert('Your comments have been submitted. Thank you for your feedback.'); location.reload();">


But the onclick happens before the submit, so refreshing the page there doesn't really work - it doesn't show the new info. And after hitting submit I just get a blank web page.

Is there any way to do this within my perl script instead, after it does all the form processing?

Sixtease
05-06-2009, 02:32 AM
The action attribute of the form says where the browser will send the data and it's also the page that gets loaded. Simply put all you need into this page -- i.e. the script for processing the form data could look like
# process the form data...
print "<p>Your comments have been submitted</p>
<p><a href=\"...\">continue</a></p>";

Another way around is to send the form with AJAX. Then the page won't get reloaded and you have full control of what to do next.