henryaaron
henryaaron

Reputation: 6192

JavaScript redirect with variables

So I have this JavaScript function getSearchVariable which basically acquires a variable from the URL using raw Javascript.

I need to redirect the user to a page with a URL with some static text before the variable and after the variable.

document.location.href="http://example.com/tracer?="+(getSearchVariable('Track')+"&tba=N"

Any idea on why something like the code above won't work?

Upvotes: 0

Views: 4742

Answers (2)

alex
alex

Reputation: 490143

Your parenthesis are not balanced.

document.location.href=
    "http://example.com/tracer?="+(getSearchVariable('Track')+"&tba=N"
//                                ^
//                                |
//                                +--- Remove this guy.

Upvotes: 3

epascarello
epascarello

Reputation: 207501

Because you are missing a )

document.location.href="http://example.com/tracer?="+(getSearchVariable('Track')+"&tba=N"
                                                     ^1                ^2      ^2

it should be

document.location.href="http://example.com/tracer?="+(getSearchVariable('Track'))+"&tba=N"

Upvotes: 2

Related Questions