By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,043 Members | 1,126 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,043 IT Pros & Developers. It's quick & easy.

IE form submission cannot change location.href?

P: n/a
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?
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Bryan" <br*@itnisk.com> wrote in message
news:9e************************@posting.google.com ...
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>
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.