Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 17th, 2004, 10:50 AM
Registered User
 
Join Date: Feb 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Javascript nightmares!!!

Help... This is driving me nuts, none of the books I have cover this and can't find anywhere on the net. Feel free to tell me I'm stupid if you feel it is necessary.

The problem I have is this. Am building a page which uses javascript dalog boxes, nice and simple I thought... But how do you get the response back from javascript into PHP so it can be used for conditional responses?

snippet of code here:

if ($notices['nb_keepalive']){
print "<script language=\"javascript\">messageStr=\"This message id: ".$notices['nb_id']." is marked to stay active, are you sure you wish to delete?\";deltrue=confirm(messageStr);</script>";}

the intention is to readback the result from the javascript:confirm dialog and use that to continue to process the database info.

Anyone who can help will have my undying gratitude!!!

can't offer enything else unfortunately!

Cheers

Paul:(
 
Old February 17th, 2004, 02:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can't do that. PHP executes on the server, and generates the HTML and Javascript text that's sent to the client. By the time the client starts executing the javascript, the PHP script has long since finished executing.

If you need to have some sort of user interaction, it needs to happen in multiple requests.

That is, generate a PHP page with a form or something saying "Are you sure?" and when the user submits that, go ahead and delete your thing.


The other (and easier to implement) option is to embed a javascript event to your original form page to pop up an "Are you sure?" dialog before submitting the form. If the user clicks "yes", then Javascript will go ahead and submit the form. If the user clicks "no", the form is not submitted.


Take care,

Nik
http://www.bigaction.org/
 
Old February 17th, 2004, 02:47 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I should say "An other option" not "The other option", because there's more than just two ways of solving this problem, but these two are (imho) the most straight forward.

Take care,

Nik
http://www.bigaction.org/
 
Old February 17th, 2004, 04:16 PM
Registered User
 
Join Date: Feb 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Cheers for that, should have made the connection myself. Next best solution would be to generate a pop-up and 'POST' back to the main page. All submissions are set to PHP_SELF.

Gonna have to think on this one a bit I think!

 
Old February 19th, 2004, 07:38 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When the user submits a form in the popup page, have Javascript trigger a page refresh in the original page.


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
stop current javascript function using javascript sakthi Javascript 3 June 2nd, 2008 03:30 PM
"text/javascript" and "javascript" rupen Javascript 1 June 24th, 2005 07:20 AM
new to javascript shankhan Javascript 2 April 26th, 2005 05:34 AM
Table nightmares >:( Snib HTML Code Clinic 30 July 6th, 2004 04:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.