Click to See Complete Forum and Search --> : IE redirect and forms


fuwsdotnet
10-16-2003, 11:57 AM
does anybody know anything about any bugs that IE may have with javascript redirects inside of a form. for example

=========================================
<form name=form onsubmit=redirect()>
<input type="text" name="text1" size="20"><br>
<input type="text" name="text2" size="20"><br>
<input type="submit" value="submit">
</form>
<SCRIPT language="JavaScript">
function redirect()
{
document.location.href = "index.html";
return;
}
</SCRIPT>
=========================================
put this simple code into a browser and run it in IE. IE just reloads the page and skips over the redirect. ANybody kow why this is? Now take this codee and run it in netscape. The page works just fine. If anybody knows of a fix for this or any ideas why this does not work in IE would be greatly appreciated.

john

requestcode
10-16-2003, 01:14 PM
I think you want:
window.location.href = "index.html"; or this will work also:
location.href = "index.html";

If you leave "window" off it is assumed.

You could also do this and not use javascript:
<form name=form method="post" action="index.html">

fuwsdotnet
10-16-2003, 01:42 PM
Originally posted by requestcode
:
window.location.href = "index.html";


window and document are the same thing so both will work.
Originally posted by requestcode
:
You could also do this and not use javascript:
<form name=form method="post" action="index.html">

I am doing a redirect in javascript andf not the form because on a more advanced page the url is dynamicaly built depending on what the user has choosen too enter. I am positive that this code is proper syntax. It works fine outside of a form.

While testing, no IE versions like this and they just reload the current page. Some netscapes will handle it and others may not (Netscape 7.1 does not). opera Version 7.21 does the redirect.

I thought a redirect was standard code and would work on any browser. The redirects do work on all browsers it just doesnt work when thrown into a form.

http://helix.pct.edu/wenjoh26/survay/survay_01bata.html

is the page I am working on, check it out if you wish. Dont be surprized if it isnt pretty (im still working on it). If your browser redirects (expect a db error) post what browser you are using.


john

requestcode
10-16-2003, 02:48 PM
How about this way:
<html>
<head>
<title>Test</title>
</head>
<body>
<form name=form>
<input type="text" name="text1" size="20"><br>
<input type="text" name="text2" size="20"><br>
<input type="button" value="submit" onClick="redirect()">
</form>
<SCRIPT language="JavaScript">
function redirect()
{
window.location.href = "page1.html";
//return;
}
</SCRIPT>
</body>
</html>