Jump to content

create hyperlink from textbox value


anthonyv

Recommended Posts

Hi all,

 

wondering if you could assist me with something i know is quite simple, though i don't know the correct syntax to code it myself...

 

I have a simple html page with a single textbox.

I require that a user enters a value into the textbox (their User ID) and this will be used to create a hyperlink.

 

So, if the user entered “anthony” into the textbox, the “go” (submit) button beside it would open the page:

http://www.anthony.mydomain.com in a new browser window.  If they entered “Jimmy” into the textbox, the “go” button b would open the page http://www.harry.mydomain.com in a new browser window.

 

I kno this is real simple, but as i mentioned, I just don’t know the correct javascript syntax to read and parse the textbox values.

 

This is a non-working example of what i think it will look like... i'd be grateful if someone could correct me (this is how i learn).

 


<html>
<head>
<title>New Page 1</title>
</head>

<body>

<script language=javascript>
function getlink (form) {
  var thelink = form.userid.value;
  }
</script>

<form name="form" method="POST" action="javascript:getlink()">
<p align="center">Please enter your User ID to view<br>
your personalised preview:<br>
<input type="text" name="userid" size="20"><br>
<input type="submit" value="Submit" name="getlink" onclick="<a href="http://www.$thelink.mydomain.com"></p>
</form>

</body>

</html>

 

Any assistance would be much appreciated.

 

Thanks in advance,

 

Anthony.

Link to comment
https://forums.phpfreaks.com/topic/51823-create-hyperlink-from-textbox-value/
Share on other sites

Ok, searching google i got this far, but something wrong in creating the correct hyperlink:

 

<html>
<head>
<title>New Page 1</title>
</head>

<body>

<script language="Javascript">
function goURL()
string UserID;
UserID = userid.textbox.value;
location.href="http://www.?id=" + txtTemp;.google.com;
</script>

<form name="form" method="POST" action="goURL()">
<p align="center">Please enter your User ID to view<br>
your personalised preview:<br>
<input type="text" name="userid" size="20"><br>
<input type="submit" value="Submit"></p>
</form>

</body>

</html>


<html>
<head>
<title>New Page 1</title>
</head>

<body>

<script language=javascript>
function getlink (f) {
var url = f.userid.value;
url = "http://www." + url + ".mydomain.com";

window.open(url, 500, 500);	//go google search for more of this function's properties.
}
</script>

<form name="form" method="POST" action="javascript:getlink(document.form)">
<p align="center">Please enter your User ID to view<br>
your personalised preview:<br>
<input type="text" name="userid" size="20"><br>
<input type="submit" value="Submit" name="getlink" onclick="<a href="http://www.$thelink.mydomain.com"></p>
</form>

</body>

</html>

 

Buddy... hope this help you.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.