Hyperlink in a TextBox - Possible?

T

theintrepidfox

Dear Group

Simple question or maybe not.
I have a text box that contains a hyperlink e.g. http://www.mysite.com.
Is it possible to get that hyperlink to work so when a user clicks on
it it brings up this website?

I know about link labels etc but in this case this is a contact form
which is used to view and update information so if it would be a link
label the user wouldn't be able to enter the hyperlink in the first
place. Just thought whether there's a possible way instead of creating
two controls, a textbox that is displayed for data entry and a link
label for viewing the data.

Thanks very much for your help & efforts!

Best Regards,

Martin
 
Joined
Mar 15, 2011
Messages
1
Reaction score
0
I realize this is a very old thread, but I have a VERY easy to implement solution for this requirement.

Imagine for a moment that you have a text area on a form that someone can enter a URL into... handling the text entry is of course handled for you by the input type="text", but wouldn't it be nice if someone could click on the url in that text box and have the browser take them there.

The following approach will address that requirement and it has been tested on IE, Safari, Chrome and Firefox and worked on all of them.

Add the following script to the top of your page.

<!-- -->
<!-- Following script used to open a child window -->
<!-- -->
<script language="javascript">
function Reload() {
window.location.reload();
}
function NewWindow(mypage, myname, w, h, scroll, statusbar, tool, menu, location) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+', status='+statusbar+',toolbar='+tool+', menubar='+menu+', location='+location+',resizable=no';
win = window.open(mypage, myname, winprops);
if (parseInt(navigator.appVersion) >= 4) {
win.window.focus();
}
}
</script>
<script language="javascript">
function Close()
{
self.close();
if (opener && !opener.closed)
{
opener.Reload();
}
}
</script>


Next, modify your input type=text to include invocation of the script.

For example, this is what the input tag looks like without the hyperlink support.

<input type="text" name="orgurl" size="30" tabindex="2" value="http://url">
... and as you would expect, the text is displayed in this text box as "http://url" but there is no hyperlink capability.

Now modify the input tag to invoke the script as follows (adding the onClick):

<input type="text" name="orgurl" size="30" tabindex="2" value="http://url" onClick="javascript:NewWindow('http://url,'name','1100','900','yes','yes','yes','yes', 'yes')">

The text will show as before, and if you click on that textbox, a window opens with the target page in it. To be clear, the cursor doesn't change when you do a mouseover of the text box, but if you click on the text box... off it goes.

(change the parameters you send to the script as needed of course)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top