Adjust a link?

JingleBells

FH is my second home
Joined
Mar 25, 2004
Messages
2,224
Do you have any server-side scripting capabilities? (i.e.: PHP/ASP/Perl/JSP) as that would be the optimal way to do this, however it is possible with client-side javascript, like so:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> 
<title>Test Form</title>
<style type="text/css">
#user_link { display: none; }
</style>
<script type="text/javascript">
function changeLink(theForm) {
	var baseUrl = "http://www.example.com/"; //Change this to whatever you want ensuring it is in quotes
	var userUrl = theForm.user.value;
	if(userUrl.length!=0) {
		document.getElementById("user_link").style.display = "inline";
		document.getElementById("user_link").setAttribute("href", baseUrl + userUrl);
	}	
	return false;
}
</script>
</head>
<body>
<form onsubmit="return changeLink(this)" action="" method="get">
<p>Enter Your Name:<br/>
<input type="text" name="user" size="20" />
<input type="submit" value="Show Link"/>
</p>
<a href="http://www.example.com/link/" id="user_link">Link to a site</a>
</form>
</body>
</html>
 

Users who are viewing this thread

Top Bottom