Chris Wilson Chris Wilson - 1 year ago 76
PHP Question

Prompt not working with IF statement

Again, I'm very new to programming with PHP and JS. I pulled off a piece of code that is a JS prompt function within PHP to confirm a modification to data. The $confirmdelete variable is indeed "YES" when I type that in the prompt... (I checked it with an echo), but it keeps producing the "MODIFICATION ABORTED" message no matter what (and of course not changing the data).

Is my IF statement bad? Hope it is just a newb typo... Is this even a good way to do this? Thanks for any help...

//prompt function
function prompt($prompt_msg){
echo("<script type='text/javascript'> var answer = prompt('".$prompt_msg."'); </script>");
$answer = "<script type='text/javascript'> document.write(answer); </script>";

$prompt_msg = "Are you SURE you wish to make a modification? Type YES to confirm: ";
$confirmdelete = prompt($prompt_msg);
if ($confirmdelete != "YES") {
<a href='index.php'>RETURN TO MAIN PAGE</a>";

Answer Source


You cannot do that.

When the PHP code is outputted -- it is done. There is no more talking back to the server unless you add some AJAX handlers.

The only think your code outputs is this:

<script type='text/javascript'> var answer = prompt('Are you SURE you wish to make a modification? Type YES to confirm: '); </script>MODIFICATION ABORTED <br><br>
                <a href='index.php'>RETURN TO MAIN PAGE</a>


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download