I have a html form which calls a servlet when a submit button is clicked.Now,I want to display a CONFIRM FORM before calling the servlet. The form must call the servlet only if the OK button is clicked in the confirm form.
Any suggestions please!!
Display confirm form before calling a servlet
Moderator: General Moderators
-
tinnumaverick
- Forum Newbie
- Posts: 7
- Joined: Fri Oct 01, 2010 2:32 pm
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Display confirm form before calling a servlet
Code: Select all
function onSubmit()
{
if (confirm('Press OK to run servlet')) {
//run servlet
return true;
}
return false;
}
<form ...>
<input type="submit" onclick="return onSubmit();" value="Submit">
</form>-
tinnumaverick
- Forum Newbie
- Posts: 7
- Joined: Fri Oct 01, 2010 2:32 pm
Re: Display confirm form before calling a servlet
Thank you for your reply!!
<?php
function onSubmit()
{
if (confirm('Press OK to run servlet')) {
// HOW CAN I CALL THE SERVLET FROM HERE?? SHALL I HAVE TO MAKE ANOTHER <FORM> </FORM> HERE
return true;
}
return false;
}
$non1=$_GET['file'];
echo "<form action=\"http://test.lib.siu.edu:8080/comline/n\" method=\"POST\">"; //presently calling the servlet from here
echo "<p>File to be deleted <input type=\"text\" name=\"filename1\" value=\"$non1\" readonly size=\"30\"></p>";
echo "<input type=\"submit\" value=\"Delete object\" onClick=\"return onSubmit()\"> ";
echo "</form>";
?>
<?php
function onSubmit()
{
if (confirm('Press OK to run servlet')) {
// HOW CAN I CALL THE SERVLET FROM HERE?? SHALL I HAVE TO MAKE ANOTHER <FORM> </FORM> HERE
return true;
}
return false;
}
$non1=$_GET['file'];
echo "<form action=\"http://test.lib.siu.edu:8080/comline/n\" method=\"POST\">"; //presently calling the servlet from here
echo "<p>File to be deleted <input type=\"text\" name=\"filename1\" value=\"$non1\" readonly size=\"30\"></p>";
echo "<input type=\"submit\" value=\"Delete object\" onClick=\"return onSubmit()\"> ";
echo "</form>";
?>
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Display confirm form before calling a servlet
My comment was a little misleading. By returning true in the onSubmit() function, the form will be submit, thus, running your servlet. So basically, you don't need to change anything -- I just wanted to show you when the servlet would be run. You can actually simplify the function to
Code: Select all
function onSubmit()
{
return confirm('Press OK to run servlet');
}-
tinnumaverick
- Forum Newbie
- Posts: 7
- Joined: Fri Oct 01, 2010 2:32 pm
Re: Display confirm form before calling a servlet
Thank you i got the solution
<?php
$non1=$_GET['file'];
echo "<form action=\"http://test.lib.siu.edu:8080/comline/n\" method=\"POST\">";
echo "<p>File to be deleted <input type=\"text\" name=\"filename1\" value=\"$non1\" readonly size=\"30\"></p>";
echo "<input type=\"submit\" value=\"Delete object\" onClick=\"return confirm(
'Are you sure you want to delete the object?');\"> ";
echo "</form>";
?>
<?php
$non1=$_GET['file'];
echo "<form action=\"http://test.lib.siu.edu:8080/comline/n\" method=\"POST\">";
echo "<p>File to be deleted <input type=\"text\" name=\"filename1\" value=\"$non1\" readonly size=\"30\"></p>";
echo "<input type=\"submit\" value=\"Delete object\" onClick=\"return confirm(
'Are you sure you want to delete the object?');\"> ";
echo "</form>";
?>