Pass multiple variables in url javascript
I am trying to have 2 variable values passed in a url, which url will be redirected after. How can I insert them in a JavaScript string? Show
I have:
and want something like: In PHP I would go with that code for example:
Matmarbon 3,7792 gold badges28 silver badges42 bronze badges asked Jan 7, 2012 at 11:26
You can add strings in JavaScript, So what you want is probably But you should ever escape vars especially if they come from
And then
To redirect you can use
answered Jan 7, 2012 at 11:32
MatmarbonMatmarbon 3,7792 gold badges28 silver badges42 bronze badges use the ampersand to split vars
Could be made more sopisticated, but that in essence is what you need answered Jan 7, 2012 at 11:29
gotofritzgotofritz 3,2951 gold badge30 silver badges47 bronze badges 1 JavaScript doesn't do string interpolation. You have to concatenate the values.
answered Jan 7, 2012 at 11:30
QuentinQuentin 876k121 gold badges1172 silver badges1287 bronze badges I'm passing a variable to another page in a url using sessions like this but it seems that I can't concatenate another variable to the same url and retrieve it in the next page successfully Page 1 session_start(); $event_id = $_SESSION['event_id']; echo $event_id; $url = "http://localhost/main.php?email=" . $email_address . $event_id; Page 2 if (isset($_GET['event_id'])) { $event_id = $_GET['event_id'];} echo $event_id; echo $event_id shows an error Undefined variable on page 2 but if I use just the event_id in the $url like here $url = "http://localhost/main.php?event_id=" . $event_id; That works fine, but I need to be able to use both variables in the url so that page 2 can retrieve get them. Vineetunread, Dec 4, 2011, 3:10:59 AM12/4/11 to web2py-users Anthonyunread, Dec 4, 2011, 3:37:58 AM12/4/11 to
|