2

I am using something the below code to pass a single value via query string to my html page on button click using Javascript function.

window.location.href("somepage.html?w1=" + hello); 

The above code is working fine.

But when I am trying to append second variable with this URL, nothing happens on click of the button.

window.location.href("somepage.html?w1=" + hello + "&w2=" + world);

What am I doing wrong here?

6
  • 2
    Is world a defined variable? Commented Jul 31, 2014 at 12:06
  • 3
    It's window.location.href = "somepage.html?w1="+ hello +"&w2="+ world; I.e. your "first code" is not working (I tested it and got "string is not a function"). Commented Jul 31, 2014 at 12:07
  • window.location.hrefis not a function. There is no way that'll work. Commented Jul 31, 2014 at 12:22
  • @Brian World and Hello are strings, not variables Commented Jul 31, 2014 at 12:24
  • But it is working for single values. Also, I have tried using window.location.href="something/html?....." for passing multiple values. It dint work either. Nothing happens on button click Commented Jul 31, 2014 at 12:28

1 Answer 1

1

href is a property. try assigning the value like this:

window.location.href = "somepage.html?w1=" + hello + "&w2=" + world;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.