Page 1 of 1

Display confirm form before calling a servlet

Posted: Sun Oct 03, 2010 10:46 pm
by tinnumaverick
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!!

Re: Display confirm form before calling a servlet

Posted: Sun Oct 03, 2010 11:48 pm
by John Cartwright

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>
??

Re: Display confirm form before calling a servlet

Posted: Mon Oct 04, 2010 12:11 pm
by tinnumaverick
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>";

?>

Re: Display confirm form before calling a servlet

Posted: Mon Oct 04, 2010 12:13 pm
by John Cartwright
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');
}

Re: Display confirm form before calling a servlet

Posted: Mon Oct 04, 2010 12:46 pm
by tinnumaverick
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>";

?>