HTML / Javascript - How to input Go to Url ?

kingthebadger

Newbie
Joined
Jun 25, 2004
Messages
1,536
Reaction score
0
Basically i want people to enter any url (like an address bar) and click Go! to visit the url they have typed in. can someone give me the information to input this onto my site?

ve tried the following :


<html>

<head>
<script type="text/javascript" language="JavaScript">
<!--
function GoToURL() {

var URLis;
URLis = document.myForm.Dest.value

if (URLis == "" || URLis.length <= 8)
{
alert('\nOops!\n\nYou must enter a valid URL');
}
else
{
this.location.href = URLis;
}
}
//-->
</script>
</head>

<body>

<form name="myForm">
<input type="text" value="http://www." name="Dest">
<input type="button" value="go to url" onClick="GoToURL()">
</form>

</body>

</html>
 
kingthebadger said:
Basically i want people to enter any url (like an address bar) and click Go! to visit the url they have typed in. can someone give me the information to input this onto my site?

ve tried the following :


<html>

<head>
<script type="text/javascript" language="JavaScript">
<!--
function GoToURL() {

var URLis;
URLis = document.myForm.Dest.value

if (URLis == "" || URLis.length <= 8)
{
alert('\nOops!\n\nYou must enter a valid URL');
}
else
{
this.location.href = URLis;
}
}
//-->
</script>
</head>

<body>

<form name="myForm">
<input type="text" value="http://www." name="Dest">
<input type="button" value="go to url" onClick="GoToURL()">
</form>

</body>

</html>


try onclick="return GoToURL()"

And you need a semi-colon after the line URLis = document.myForm.Dest.value
 
We do have a forum dedicated to coding you know.
 
mortiz said:
We do have a forum dedicated to coding you know.
thought id get more people noticed here =) neways, could you guys paste the whole code so i can just input it into macromedia. thanks
 
Here you go:

<html>

<head>
<script type="text/javascript" language="JavaScript">
<!--
function GoToURL() {

var URLis;
URLis = document.myForm.Dest.value;

if (URLis == "" || URLis.length <= 8)
{
alert('\nOops!\n\nYou must enter a valid URL');
}
else
{
this.location.replace(URLis);
}
}
//-->
</script>
</head>

<body>

<form name="myForm">
<input type="text" value="http://www." name="Dest">
<input type="button" value="go to url" onClick="return GoToURL()">
</form>

</body>

</html>

:)
 
Lex Luthor said:
Here you go:

<html>

<head>
<script type="text/javascript" language="JavaScript">
<!--
function GoToURL() {

var URLis;
URLis = document.myForm.Dest.value;

if (URLis == "" || URLis.length <= 8)
{
alert('\nOops!\n\nYou must enter a valid URL');
}
else
{
this.location.replace(URLis);
}
}
//-->
</script>
</head>

<body>

<form name="myForm">
<input type="text" value="http://www." name="Dest">
<input type="button" value="go to url" onClick="return GoToURL()">
</form>

</body>

</html>

:)

I don't know jack about javascript, but shouldn't that onClick="return GoToURL()" be inside the javascript tags for it to work?
 
Dgenatron said:
I don't know jack about javascript, but shouldn't that onClick="return GoToURL()" be inside the javascript tags for it to work?

No, that's how it's supposed to be. HTML and javascript are very closely linked. You can edit the html from within the javascript, and make function calls to the javascript functions within events of html objects... I think. Well at least it works :p.
 
You should use getElementById instead, it will work on all browsers and is w3c standard.

Code:
<html>
<head>
<script type="text/javascript" language="JavaScript">
function GoToURL(){
	var URLis;
	URLis = document.getElementById("Dest").value;

	if (URLis == "" || URLis.length <= 8){
		alert('You must enter a valid URL');
	}else{
		document.location.href=URLis;
	}
}
</script>
</head>
<body>

<form name="myForm">
<input type="text" value="http://www." name="Dest" id="Dest">
<input type="button" value="go to url" onClick="GoToURL();">
</form>

</body>
</html>
 
Code:
<?php if ($_SERVER ['REQUEST_METHOD'] != 'POST') { ?>

<html>
<head>
<title>Redirection</title>
</head>
<body>

<form name="myForm" method="post">
<input type="text" value="http://www." name="Dest">
<input type="submit" value="Go to url">
</form>

</body>
</html>

<?php

} else {

$dest = $_POST['Dest'];

header("Location: $dest");
exit; 

} ?>

Thats a PHP Version if you want to use it.
 
Back
Top