Hyperlink in Javascript


I want to add Hyperlink input field just like the Direct Link & Forum Link as shown in the code below :

I tried to do it just like the Forum Link but it's come out as active link. I just want to paste the hyperlink code.

Thank you so much for your time.
function test_completed(result1, results2) {
        var myid = getTestID(); 
        if(myid!=-1) {
        document.getElementById("mypic").innerHTML = "<img src='http://www.mywebsite.com/result/" + myid + ".png'><br>" + "Direct Link:<br><input type='text' readonly='readonly' size='37' value='http://www.mywebsite.com/result/" + myid + ".png'<br>" + "Forum Link:<br><input type='text' readonly='readonly' size='37' value='[URL=http://www.mywebsite.com][IMG]http://www.mywebsite.com/result/" + myid + ".png[/IMG][/URL]'<br>";

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gurvinder Pal SinghCommented:
Adding a link is as simple as below

first create a link:

var link=document.createElement('a');

Then set this place this link where ever you want, say if you want to put in a div section then,
document.getElementById('divId').appendChild ( link );

see this link for reference

let me know if this helped
Dido123Author Commented:
I don't want it as active link. I just want it to be as text in the input field :

"Forum Link:<br><input type='text' readonly='readonly' size='37' value='[URL=http://www.mywebsite.com][IMG]http://www.mywebsite.com/result/" + myid + ".png[/IMG][/URL]'<br>"

Just like the link above. The problem is, when I did it exactly like the above it went as active link .. not just text in the input field.

I hope that explained what I want to do.

Thanks for your efforts.
use like this

<span onclick="window.location='http://google.com'">google</span>
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Dido123Author Commented:
Any answers please?
inordere to send it as an text before sending encode it with javascript escaspe()  function
Dido123Author Commented:
@manjunathub can you show me that with code? I'm not that good in Java.
can u tell me what exactly u want and snapshot what ur getting...
Dido123Author Commented:

I want to add hyper link in a text input field just like the one shown in first post.

The problem is when I do it just like I did the Forum Link example I get an active link not just text.

This is the Forum link code extracted from my javascript above :

Forum Link:<br><input type='text' readonly='readonly' size='37' value='[URL=http://www.mywebsite.com][IMG]http://www.mywebsite.com/result/" + myid + ".png[/IMG][/URL]

I want it a hyper link as below to be included in the inner.HTML with the rest of my code :

<a href="http://www.mywebsite.com"><img src="http://www.mywebsite.com/result/myid.png"></a>
ithink this is what u wanted to do...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
	function test_completed(result1, result2) {
			var a = document.createElement('a');
				a.setAttribute("href", document.getElementById(result1).value);
			var img = document.createElement('img');
<body onload="test_completed()">
	Forum link: <input type="text" value="" id="href"/><br/>
	Image Link: <input type="text" value="" id="img"/>
	<input type="button" onclick="test_completed('href','img')" value="click me">
	<div id="mypic" />

Open in new window

Dido123Author Commented:

How I can convert this link to text so I can paste it with the rest of my "mypic" DIV ?

<a href="http://www.mywebsite.com"><img src="http://www.mywebsite.com/result/myid.png"></a>
use this code to get the text it will work in all browsers...

function test_completed(result1, result2) {
			var text = '<a href="' + document.getElementById(result1).value +'"><img src="'+document.getElementById(result2).value+'"/></a>';

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thanks for giving points....
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.