I’m very interested in if it is possible to connect javascript variables to php. I know that in php we can write javascript code, but on the contrary we could not. To express my aim better , lets bring example like that:
<form name="some" action="<?php $_SERVER['php_self']; ?>" method="post">
<input type="submit" name="but" value="Action">
</form>
My question is how to make after pressing submit button to confirm (alert) with javascript and if it is confirmed do something (with php) and if isn’t cancel (php operation).
You can do two things to pass javascript variable to php:
You can pass it as a hidden input field and submit it using POST
<input id="myHidden" name="myHidden" type="hidden"/>Assign javascript variable to hidden input something like
var myVariable;document.getElementById("myHidden").value = myVariable;You can pass it as a query string with in your URL
As for confirming you can use javascript confirm, which will post on OK and not post/cancel on CANCEL
Something like: