ibexy Posted February 15, 2008 Share Posted February 15, 2008 I have the following which generates a dialogue box from php with an [ok] and a [cancel] button. Its working but I cant figure out how to transfer the value of (x) to php so I can stop or go on with the action. echo("<script type='text/javascript'>var x=window.confirm('Would you like to continue?') </script>"); I have tried to test for (x) like this but its not working: if (x) { blah blah blah What am I doing wrong here? Quote Link to comment Share on other sites More sharing options...
priti Posted February 15, 2008 Share Posted February 15, 2008 Hi, Those events can be handled with javascript??? Then handle the functions from there. Regards Quote Link to comment Share on other sites More sharing options...
ibexy Posted February 15, 2008 Author Share Posted February 15, 2008 Yes, like I said, its working fine from javascript. The box is displaying fine but the rest of the program is in php. How can I make php test for the variable (x) which is getting its value from the javascript. echo("<script type='text/javascript'>var x=window.confirm('Would you like to continue?') </script>"); Below is a break down of what I want to do: if (x) = ok carry out the action } else { abort } php does not seem to recognise (x). Is that because its getting its value from within a javascript code? or probably, am getting it all wrong. Someone help a newbie! Quote Link to comment Share on other sites More sharing options...
nikefido Posted February 15, 2008 Share Posted February 15, 2008 you can't pass values from php to javascript and visa-versa that easily. (altho it would be nice). be aware that you shouldn't rely on javascript as users can shut it off in their browsers. Quote Link to comment Share on other sites More sharing options...
ibexy Posted February 15, 2008 Author Share Posted February 15, 2008 thanks for that infor. Is there no other way to create an [Ok] [Cancel] dialogue box in php? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 15, 2008 Share Posted February 15, 2008 The only way you can pass information from Javascript to PHP is to use AJAX techniques. PHP and Javascript run at two different contexts. PHP runs on the server and when it's all done, the browser see the output and if there is any Javascript it is executed. Ken Quote Link to comment Share on other sites More sharing options...
priti Posted February 18, 2008 Share Posted February 18, 2008 thanks for that infor. Is there no other way to create an [Ok] [Cancel] dialogue box in php? Hi, Well i have done it but thru AJAX . So it made my life easier :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.