IE form submission cannot change location.href?

B

Bryan

Hi, I have a form that I want to click a button on and cause the
location.href to change. this is what I used:

the function:

function testform(){
location.href="http://www.google.com"

}

the form:
<form >
<INPUT TYPE=submit NAME=foo VALUE=Proto onClick="testform()">


</form>

I have of course done variations of the above, this works in firefox
and mozilla, in IE it does nothing, what is the bug or feature I am
dealing with here?
 
M

Murray

Bryan said:
Hi, I have a form that I want to click a button on and cause the
location.href to change. this is what I used:

the function:

function testform(){
location.href="http://www.google.com"

}

the form:
<form >
<INPUT TYPE=submit NAME=foo VALUE=Proto onClick="testform()">


</form>

I have of course done variations of the above, this works in firefox
and mozilla, in IE it does nothing, what is the bug or feature I am
dealing with here?

I think the problem is that you're using type="submit". The function works,
but the button also submits the form which seems to override the window.href
call. Change it to type="button" and it should work. Or leave it as submit
if you need to, and change the onclick to "testform(); return false;"

Incidentally, a nicer way to do this without even using javascript would be
to specify the href in the form's action

<form action="http://www.google.com" method="get">
<input type="submit" value="Proto"/>
</form>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top