Hyperlink in Javascript

Hi,

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

Dido123Asked:
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');
link.setAttribute('href',"http://google.com");

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
http://www.dustindiaz.com/add-remove-elements-reprise/

let me know if this helped
0
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.
0
manjunathubCommented:
use like this

<span onclick="window.location='http://google.com'">google</span>
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

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>
0
manjunathubCommented:
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">
<head>
<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');
				img.setAttribute("src",document.getElementById(result2).value);
			a.appendChild(img);
			document.getElementById('mypic').appendChild(a);
		}
	//window.onload=
</script>
</head>
<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" />
	
</body>
</html>

Open in new window

0
Dido123Author Commented:
manjunathub,

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>
0
manjunathubCommented:
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>';
			document.getElementById('mypic').appendChild(document.createTextNode(text));
		
		}

Open in new window

0

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
manjunathubCommented:
thanks for giving points....
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.