Use parameters in window.location.replace
I have the following script that works great:
if(error1 == 1){
window.alert('You have already signed up!');
window.location.replace('index.php');
}
But when I want to use the following url instead of index.php it doesn't override the parameters:
if(error1 == 1){
window.alert('You have already signed up!');
window.location.replace('http://polimovie.deib.polimi.it/Version3/index.php?campaign=".$Campaign_id."&worker=".$Worker_id."');
}
This code redirects me to http://polimovie.deib.polimi.it/Version3/index.php?campaign=.$Campaign_id.&worker=.$Worker_id.
, while I need the parameters to be replaced with their actual numbers.
I know I can use a php header, I have also used it in my php codes like this and with this working fine:
echo "<script>alert('PLEASE SIGN UP FIRST!');window.location = 'http://polimovie.deib.polimi.it/Version3/index.php?campaign=".$Campaign_id."&worker=".$Worker_id."';</script>";
but I would like to know how I can use the parameters using window.location.replace.
Thank,
source to share
Try the following:
if(error1 == 1){
window.alert('You have already signed up!');
window.location.replace('http://polimovie.deib.polimi.it/Version3/index.php?campaign=<?php echo $Campaign_id; ?>&worker=<?php echo $Worker_id; ?>');
}
Above will work if it's a php file and not a js file
source to share
@Mona: In the code below, I have used produt_id as a javascript variable.
var product_id=1;
window.location.replace("/newpage/page.php?id=" + product_id);
So, if you compare this to your code, you need to take the values โโof your php variable into a javascript variable and then you have to pass them according to the above method I gave in the example.
Hope it makes your day!
Cheers :): P
source to share