0

I've been struggling with the following for the last 48 hours and I'm hoping someone here can dig me out of a hole;

window.open("process.php?page=g&zipcode=" + zipcode); <- I need to add a second variable to the end of this URL. I know that if I do this window.open("process.php?page=g&zipcode=" + zipcode + id); adds the variable but annoyingly directly after the first one. What I need is for it to look like this:

process.php?page=g&zipcode=33001&id=63423563

the bit I can't get is how to add the "&id=" inbetween the variables.

I really hope that make sense.

Thanks in advance

4 Answers 4

1

You're only appending them directly, not adding the necessary string between them:

window.open('process.php?page=g&zipcode='+zipcode+'&id='+id); 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, looks like I missed out the + after the first variable.
0
window.open("process.php?page=g&zipcode=" + zipcode + "&id=" +  id);

Comments

0

In javascript, + is used for both addition of numbers and concat of strings. In your question you said that you have typed as,window.open("process.php?page=g&zipcode=" + zipcode + id);
This would concat the zipcode and id, and the combination to the string.Instead you must type,

window.open("process.php?page=g&zipcode=" + zipcode +"&id="+ id);

This would concat id to its respective string i.e.&id=.You have missed it to learn.

Comments

0

+ is used to concat strings.

"process.php?page=g&zipcode=" + zipcode +"&id=" + id

3 Comments

Or as an addition operator ;)
You don't need a space before the &id= part
@BenM well it's strings addition :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.