|
-
September 28th, 2007, 02:44 AM
#1
javascript and php
hi, how can i send a confirmation dialog of javascript in php and get the respond of ok or cancel from the dialog??
thanks alot ....
0 error(s), 0 warning(s)
-
September 28th, 2007, 06:59 AM
#2
Re: javascript and php
You will have to pass it through a parameter or use AJAX.
Code:
<script type="text/javascript">
var okcancel = confirm();
var theResponse = (okcancel) ? 'yes' : 'no';
window.location = 'test.php?response=' + theResponse
</script>
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 28th, 2007, 07:54 AM
#3
Re: javascript and php
!!! thank you very much 
got it to works hehe
0 error(s), 0 warning(s)
-
September 28th, 2007, 08:03 AM
#4
Re: javascript and php
You're welcome. Good luck with the rest!
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 28th, 2007, 08:07 AM
#5
Re: javascript and php
erm.. could i continue to ask ... after i do a window.location...
how can i grab the variable from the url and set it to the window.location??
for example when the confirmation dialog is invoke the url is
test.php?abc=3&ddd=4
how can i retrieve the abc=3 and add it to the window.location?
thanks
0 error(s), 0 warning(s)
-
September 28th, 2007, 08:21 AM
#6
Re: javascript and php
Just use $_GET.
Code:
<?php
$abc = $_GET['abc']; // value will equal 3
?>
<script type="text/javascript">
window.location = 'test.php?abc=<?php echo $abc; ?>';
</script>
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 28th, 2007, 08:28 AM
#7
Re: javascript and php
my javascript is a .js file... and the function is invoke onclick of a button..
could i just add the php tag inside the .js file??
0 error(s), 0 warning(s)
-
September 28th, 2007, 08:52 AM
#8
Re: javascript and php
No. The JavaScript file is interpreted on the client side. Therefore the PHP, being server-side, cannot read it.
If you need to access the variable using JavaScript, here is a function I just made up that should help you.
Code:
function retrieveURLVariable(name){
var vURL = window.location.search.substr(1);
var vParts = vURL.split(name + "=");
vParts = vParts[1].split('&');
return vParts[0];
}
var test = retrieveURLVariable('abc');
alert(test);
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 28th, 2007, 09:09 AM
#9
Re: javascript and php
oh .. thats a good function~
if for php say i have a <a href="..test.php?abc=3>
after i do the processing how can i set back all the variable that has been passed over?
i know i could do a redirection and set it back 1 by 1 ... but i have lots of variable to do ...
is there any more efficient method?
thanks in advance ~~
0 error(s), 0 warning(s)
-
September 28th, 2007, 09:16 AM
#10
Re: javascript and php
Well, in PHP you can grab the whole query string using $_SERVER['QUERY_STRING'].
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 28th, 2007, 09:36 AM
#11
Re: javascript and php
>.< thanks alot for your help ... appreciate it. haha have just learn php for 3wks
will try to continue my work and post if face any more problem thankS!
0 error(s), 0 warning(s)
-
September 28th, 2007, 10:15 AM
#12
Re: javascript and php
You're welcome. 
If you have more problems, create a new thread. Each thread should be a different problem.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|