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 ....
Printable View
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 ....
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>
!!! thank you very much :)
got it to works hehe
You're welcome. Good luck with the rest! :wave:
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
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>
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??
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);
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 ~~
Well, in PHP you can grab the whole query string using $_SERVER['QUERY_STRING'].
>.< 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!
You're welcome. :wave:
If you have more problems, create a new thread. Each thread should be a different problem.