0

Probably a stupid question but I don't often use javascript and was puzzled why the following code doesn't work..

var loc = document.forms["myForm"]["sites"].value;
//loc = 'http://www.sites.com'
window.location(loc); 

I've done quite a few searches and was surprised to see this hadn't come up before.

Thanks,

1
  • This is called from: <form name="myForm" action="" onsubmit="va()" method="post"> Commented Apr 13, 2012 at 15:35

2 Answers 2

2

window.location is an object, not a function.

Try this instead:

window.location.href = loc;

or if you want to replace the current history entry:

window.location.replace(loc); 
Sign up to request clarification or add additional context in comments.

Comments

0

Try to use this:

window.location.href = loc

5 Comments

Well you can try window.top.location.href = loc but it's strange. Everything should work.
<select name="jump" onchange="window.top.location.href=+this.value;"> <option value="site.net/"></option> </select>
you forget http in site url
yeah, that was just fast typing. I've no idea why this is not working
try this <select name="jump" onchange="window.top.location.href=this.value;"><option value=""></option><option value="http://site.net/">My site</option></select>​

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.