Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with javascript redirect

Status
Not open for further replies.

kraznodar

Programmer
May 13, 2010
4
US
I'm trying to get a simple textbox and button combo to build a url and redirect the current browser window to this url. Here is what i have tried so far:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<script type="text/javascript" language="JavaScript">
function GoIntegrify(){
var obj = document.getElementById('rfcname');
alert(obj.value);
var key = obj.value;
if(key != "") {
url=" + key
document.location.href=url; //Nothing happens
window.location.replace(url); //Nothing happens
window.location.href = url; //Nothing happens
window,location = url; //Nothing happens
top.location.href = url; //Nothing happens
alert(url); //url has the correct path!!
}
}
</script>
<title>Start IT RFC</title>
</head>

<body>

<form id="form1">
Please enter the name you would like for the new Integrify request.
<br>
<input type="Text" name="rfcname" align="LEFT" size="27" maxlength="60">
  
<INPUT TYPE="SUBMIT" NAME="action" VALUE="Submit" onclick="javascript:GoIntegrify();"></form>

</body>

</html>

So far I get a whole lot of nothing happening. What am I doing wrong?
 
window.loation is correct. However you have comma instead of a period there

window[red],[/red]location = url;

So of course you should be getting a JS error. If you are using FF use its Error Console to look at the Js errors produced.

If you are using IE, then double click on the little golden shield icon on the left bottom corner of the browser.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks. I fixed the ',' and made it a period. I still get no redirection. Several different articles say that any one of those lines should work but none do. Any ideas?
 
I ran in FireFox and checked the error console. It said that obj was null. I added the id="rfcname" attribute to the textbox so it has an id now and that error went away.

Now I get no errors and it still does not redirect.
 
I am such a doofus!!! My input was of type submit. By changing it to "button" the javascript has time to do the redirect. All is well.
 
Either that, or return a false value, so that it doesn't submit.

You can also remove the "javascript:" protocol from the call, as its already inside a JS event (onClick) you don't need to specify it.
Code:
<INPUT TYPE="SUBMIT" NAME="action" VALUE="Submit" onClick="GoIntegrify(); [red]return false;[/red]">

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top