Page 1 of 1

PHP plus JavaScrip Confirm Box

Posted: Sun Sep 07, 2008 2:20 pm
by Patty
I am having a hard time figuring out how to use this piece of Javascript to return the value to a php variable. The following code will create an OK / Cancel message box in javascript. However, I would like to return which was chosen to a php variable. I know this can be done, I'm just not sure how.

It needs to be something like <script><?php $answer = ?> confirm(\"Delete?\");</script> but within an echo statement too!
Can someone help please?

Code: Select all

 
echo "<script>confirm(\"Are you sure you want to delete?\");</script>";//creates message box
 
//It needs to be something like 
 
echo " ?><script><?php echo '$answer =' ?> confirm(\'Are you sure you want to delete?\');</script>  <?php echo ";?> but within an echo statement too!
 
 

Re: PHP plus JavaScrip Confirm Box

Posted: Sun Sep 07, 2008 4:48 pm
by andyhoneycutt
I'm not sure i understand: are you trying to return a javascript-scope value to php, or do you just want php to echo some javascript?

-Andy

Re: PHP plus JavaScrip Confirm Box

Posted: Sun Sep 07, 2008 5:45 pm
by Patty
I have a javascript confirm box that pops up asking if the user wants to Delete. The user can answer OK or cancel. I need the response returned to a php variable. I know php is server side, but how can such be possible to prompt the user for an answer with a msg box in php?

Re: PHP plus JavaScrip Confirm Box

Posted: Sun Sep 07, 2008 11:35 pm
by starram
You can try something like this. This will return the value for a hidden field whose value u can store in php variable.

<html>
<head>
<script language="javascript">
function check()
{
var a=confirm("are u sure");
document.test.testtext.value=a;
this.form.submit();
}
</script>
</head>
<body>
<form name="test" method="" action="" >
<input type="button" name="button" onclick="return check();" />
<input type="hidden" value="" name="testtext" />
</form>
</body>
</html>