Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 17th, 2004, 10:50 AM
Registered User
 
Join Date: Feb 2004
Location: London, , United Kingdom.
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:(
Reply With Quote
  #2 (permalink)  
Old February 17th, 2004, 02:46 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
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/
Reply With Quote
  #3 (permalink)  
Old February 17th, 2004, 02:47 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
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/
Reply With Quote
  #4 (permalink)  
Old February 17th, 2004, 04:16 PM
Registered User
 
Join Date: Feb 2004
Location: London, , United Kingdom.
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!

Reply With Quote
  #5 (permalink)  
Old February 19th, 2004, 07:38 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
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/
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:23 AM.


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