0

How can i encode my parameters in javascript?

This my function and my parameter called newvalue

<script>
function selectChanged(newvalue) 
{
location.href="tester?restid=" + newvalue;
}
</script>

This is how i tried with adeneos suggestion

   window.location.href = "tester?restid=" + encodeURIComponent(newvalue);

but this does not work.

This is what i am getting:

tester?restid=38619

This is want i want

 tester%3Frestid%3D38619%21 
2
  • If the answers below aren't what you're looking for, please give us an example input and expected output. Commented May 9, 2013 at 18:39
  • I just updated it with an example Commented May 9, 2013 at 18:45

2 Answers 2

2
function selectChanged(newvalue)  {
    window.location.href = encodeURIComponent("tester?restid=" + newvalue);
}
Sign up to request clarification or add additional context in comments.

2 Comments

i am getting this is my url tester?restid=38619 ... i want the restid=38619 to be encode like this tester%3Frestid%3D38619%21
@Zaz - just include the rest in the encoding, changed the answer !
0

Try this:

location.href="tester?restid=" +encodeURIComponent( newvalue );

Comments

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.