LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [javascript] confirm button on php page (https://www.linuxquestions.org/questions/programming-9/%5Bjavascript%5D-confirm-button-on-php-page-294311/)

Erhnam 02-24-2005 08:39 AM

[javascript] confirm button on php page
 
I created a php page with a button and some extra functionality:

PHP Code:

echo "------------<br><br>";
echo 
"<form method='POST' action='function_extract.php'>";
echo 
"Reinstall: </td><td>";

echo 
"<select class='dropdown' name='tarball'>";

exec ("cd /control-panel/ | ls $mm3*-server.tar.gz"$tarlijst);
foreach (
$tarlijst as $inhoud) {
echo 
"<option value='$inhoud'>$inhoud</option>";
}

echo 
"</select>";
echo 
"<br><br><input type='submit' value='Reinstall' OnClick=\"confirmSubmit()\">";
echo 
"</form>"

Now I want to add a confirmation window before proceeding the next page (form).

I included this code

Code:

<script LANGUAGE="JavaScript">
<!--

function confirmSubmit()
{
var agree=confirm("Are you sure you wish to continue?");
if (agree)
        return true ;
else
        return false ;
}
</script>

But is doesn't seems to work very well.. At least a pop window is displayed but the will always be redirected to the next page. Anyone know exactly how this works?

bulliver 02-24-2005 01:05 PM

Try changing:
"echo "<form method='POST' action='function_extract.php'>"; "
to:
Code:

echo "<form onsubmit='return confirmSubmit();' method='POST' action='function_extract.php'>";
and "echo "<br><br><input type='submit' value='Reinstall' onClick=\"confirmSubmit()\">";"
to:
Code:

echo "<br><br><input type='submit' value='Reinstall'>";
This works for me with javascript form validation, before sending the form contents back to the php server


All times are GMT -5. The time now is 10:14 PM.