Abhay Andhariya
Abhay Andhariya

Reputation: 2157

How to Pass QueryString in window.location.href?

I have written the following javascript function

function getval(sel)
 {
    window.location.href = "Posts?Category=<%= sel %>";
 }

but the value of sel variable is not considered in querystring..

Instead of it, it takes value like following.

...../Post/Posts?Category=%3C%=%20sel%20%%3E

Can anyone help me???

Upvotes: 2

Views: 50498

Answers (2)

Matthias Tylkowski
Matthias Tylkowski

Reputation: 517

I don't know where you found this <%= sel %>, but its not the native JavaScript style of doing it. Try this:

function getval(sel)
{
    window.location.href = "Posts?Category=" + sel;
 }

Upvotes: 3

commit
commit

Reputation: 4807

Because javascript does not understands jsp scriptlet,

Try,

window.location.href = "Posts?Category=" + sel;

Upvotes: 7

Related Questions