You are not logged in.
Pages: 1
1. <script>
2. var r=confirm("Are you sure you want to delete")
3. if (r==true) {
4. alert("You selected Yes")
5. <?php $del = "yes"; ?>
6. } else {
7. alert("You selected No")
8. <?php $del = "no"; ?>
9. }
10. </script>
When PHP is included, whatever is selected (OK or Cancel), the above script will always read line 8 (php). The java lines (4 and 7) does correctly as per selection. Any solution to get php as per selection?
Markku
Offline
it's because php doesn't interact with javascript, nor the browser..
basically the php code never reaches the browser.
mayeb you could walk around it by using ajax or something, to cache the value in a session cookie. i dunno.
The.Revolution.Is.Coming - - To fight, To hunger, To Resist!
Offline
PHP code is executed before javascript code reaches user's browser
IRC: Stalwart @ FreeNode
Skype ID: thestalwart
WeeChat-devel nightly packages for i686
Offline
You could just POST the result to a controller page that then deletes the whatever, and then forwards back to the previous referring page.
Offline
You could just POST the result to a controller page...
I am not familar with the word "controller page". Can you give a sample.
Markku
Offline
head.html
<script language="JavaScript">
var r=confirm("Are you sure you want to delete")
if (r==true) {
alert("You selected Yes")
document.href="bounce.php?del=yes"
}
else {
alert("You selected No")
document.href="bounce.php?del=no"
}
</script>
bounce.php
<?php
// @session_start;
if (isset($_POST['del'])) {
if ($_POST['del'] == 'yes') ) {
// $del = 'yes';
// $_SESSION['del'] = 'yes';
// do_whatever ...
}
else {
$del = 'no';
// $_SESSION['del'] = 'no';
// do whatever ...
}
}
@header("Location: head.html") or echo "<meta http-equiv="refresh" content="2;url=head.html">";
?>
obviously that doesn't works as-is, and neither does the concept.
it's just a small demonstration on your last question.
The.Revolution.Is.Coming - - To fight, To hunger, To Resist!
Offline
You would not use POST if you put the stuff in the URL, you use GET.
PC: Antec P182B | Asus P8Z77-V PRO | Intel i5 3570k | 16GB DDR3 | GeForce 450GTS | 4TB HDD | Pioneer BDR-207D | Asus Xonar DX | Altec Lansing CS21 | Eizo EV2736W-BK | Arch Linux x86_64
HTPC: Antec NSK2480 | ASUS M3A78-EM (AMD 780G) | AMD Athlon X3 425 | 8GB DDR2 | GeForce G210 | 2TB HDD | Arch Linux x86_64
Server: Raspberry Pi (model B) | 512MB RAM | 750GB HDD | Arch Linux ARM
Offline
Thanks, noriko and vEX. I will test the solution.
Markku
Offline
ya sory i forgot which way roudn they went.. cos i usually use request...
The.Revolution.Is.Coming - - To fight, To hunger, To Resist!
Offline
Couldn't get to work, here what I am trying to do. What's missing? For my information, to read the full url of "bounce.php", how to?
head.php
<script language="JavaScript">
document.href="bounce.php"
</script>
<?php
$del=$_GET['del'];
echo "Test: $del";
?>
bounce.php
<?php
$del = "yes";
?>
Markku
Offline
what exactly are you trying to do....
btw, see my example above, you are implementing it incorrectly.
the php code u wrote needs to be in the same file.
either in head with the js, or in bounce.
The.Revolution.Is.Coming - - To fight, To hunger, To Resist!
Offline
...the php code u wrote needs to be in the same file.
either in head with the js, or in bounce.
I tried in different ways both your sample and mine. I am concluding javascript don't find the bounce.php. This is way I asked how to display the url (or path) created by document.href="bounce.php" ... to be sure the location is correct.
I am not familar with javascript. Does document.href="" do same as include() in php?
Markku
Offline
no, it changes the document's href (hypertext reference, i think) .. basically it redirects the page, much like header("Location:[*]")`php does.
what exactly happens?
does it change page? it should ...
ps:
whatever it is ur trying to do, i'm sure it can be done with forms, don't forget js isn't enabled on every webbrowser .... i personally have all plugins except mplayer+flash turned off in fx, and have no addons, or themes.
The.Revolution.Is.Coming - - To fight, To hunger, To Resist!
Offline
1. <script> 2. var r=confirm("Are you sure you want to delete") 3. if (r==true) { 4. alert("You selected Yes") 5. <?php $del = "yes"; ?> 6. } else { 7. alert("You selected No") 8. <?php $del = "no"; ?> 9. } 10. </script>
When PHP is included, whatever is selected (OK or Cancel), the above script will always read line 8 (php). The java lines (4 and 7) does correctly as per selection. Any solution to get php as per selection?
hmmm you're confused. PHP is processed before end-user's browser get the web page and run javascript. So the line 5 and 8 don't make sense.
Your js code could then submit back for php to handle the change.
BTW have you read about MVC? It can help you to build website on a clear design, and skip a lot of error/trying steps. Most of non-mvc websites I have seen are all very messy and hard to maintain and code.
Offline
i have ..
<a href="?section=gb&acc=delete" onclick="return confirm('Delete?')">Del</a>
Offline
.... onclick="return confirm('Delete?')">Del</a>
Thanks, reaper!! That solved the issue I was searching.
Markku
Offline
Pages: 1