Passing a variable via url, Javascript

Karessa
Karessa used Ask the Experts™
on
Hello! A couple of questions. The code below works great as long as the values aren't variables, but when they are variables it doesn't pass. So for example if I use the text "test" in place of thiscoursename in the url call, it works great. When I try to use the variable name, it doesn't.

Is there a special way of passing variables with javascript?

Thank you!


var thiscoursename="Test"

window.open("https://www.myurl.com/CompleteCourse/PostCompletedCourse?account=TestCo&firstname=Twenty&lastname=Eighth&coursename=thiscoursename&score=90", "_blank");
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Expert of the Year 2014
Top Expert 2014
Commented:
Break out of your string, concatenate the variable (+) and then start your string again.

window.open("https://www.myurl.com/CompleteCourse/PostCompletedCourse?account=TestCo&firstname=Twenty&lastname=Eighth&coursename=" + thiscoursename + "&score=90", "_blank"); 

Open in new window

Author

Commented:
Brilliant! Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial