473,395 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Href Links in Dynamic table

Hi,

I am creating a table dynamically in javascript.

All is fine but when I try to put any ahref link on the cell its not
taking it. I am doing like that.
var rowHead1 = document.createElement('TR');
var CellHead1 = document.createElement('TD');
var text1 = "<a href=http://www.google.com>" + someVariable + "</a>
var cellHeadText1 = document.createTextNode(text1);
CellHead1.appendChild(cellHeadText1);

But somehow when I run this example.
It shows like that in Table cell.
<a href=http://www.google.com>abc</a>

Its not converting it into a Link.

Any Idea, what's going wrong here.
Nov 12 '08 #1
5 8800
webmaniac schreef:
Hi,

I am creating a table dynamically in javascript.

All is fine but when I try to put any ahref link on the cell its not
taking it. I am doing like that.
var rowHead1 = document.createElement('TR');
var CellHead1 = document.createElement('TD');
var text1 = "<a href=http://www.google.com>" + someVariable + "</a>
var cellHeadText1 = document.createTextNode(text1);
CellHead1.appendChild(cellHeadText1);

But somehow when I run this example.
It shows like that in Table cell.
<a href=http://www.google.com>abc</a>

Its not converting it into a Link.

Any Idea, what's going wrong here.
Hi,

Not sure, but shouldn't you at least quote the hyperlink properly?
Like this:
var text1 = "<a href='http://www.google.com'>" + someVariable + "</a>";

Regards,
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Nov 12 '08 #2
On Nov 12, 12:40 pm, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
webmaniac schreef:
Hi,
I am creating a table dynamically in javascript.
All is fine but when I try to put any ahref link on the cell its not
taking it. I am doing like that.
var rowHead1 = document.createElement('TR');
var CellHead1 = document.createElement('TD');
var text1 = "<a href=http://www.google.com>" + someVariable + "</a>
var cellHeadText1 = document.createTextNode(text1);
CellHead1.appendChild(cellHeadText1);
But somehow when I run this example.
It shows like that in Table cell.
<a href=http://www.google.com>abc</a>
Its not converting it into a Link.
Any Idea, what's going wrong here.

Hi,

Not sure, but shouldn't you at least quote the hyperlink properly?
Like this:
var text1 = "<a href='http://www.google.com'>" + someVariable + "</a>";

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
I tried that too, but it still dont work.
I dont know, where I am getting wrong.
Nov 12 '08 #3
webmaniac meinte:
>>var text1 = "<a href=http://www.google.com>" + someVariable + "</a>
var cellHeadText1 = document.createTextNode(text1);
I tried that too, but it still dont work.
I dont know, where I am getting wrong.
Why should it? Anchors are not text nodes. Something like

var a = document.createElement("a");
a.href = "...";
a.appendChild(document.createTextNode("whatever");
CellHead1.appendChild(a);

Your "approach" requires to fill the (non-standard) innerHTML property
of CellHead1.

Gregor
Nov 12 '08 #4
webmaniac schreef:
On Nov 12, 12:40 pm, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
>webmaniac schreef:
>>Hi,
I am creating a table dynamically in javascript.
All is fine but when I try to put any ahref link on the cell its not
taking it. I am doing like that.
var rowHead1 = document.createElement('TR');
var CellHead1 = document.createElement('TD');
var text1 = "<a href=http://www.google.com>" + someVariable + "</a>
var cellHeadText1 = document.createTextNode(text1);
CellHead1.appendChild(cellHeadText1);
But somehow when I run this example.
It shows like that in Table cell.
<a href=http://www.google.com>abc</a>
Its not converting it into a Link.
Any Idea, what's going wrong here.
Hi,

Not sure, but shouldn't you at least quote the hyperlink properly?
Like this:
var text1 = "<a href='http://www.google.com'>" + someVariable + "</a>";

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare

I tried that too, but it still dont work.
I dont know, where I am getting wrong.
Ahum, sorry.

You know this feeling you are knew how something worked but totally
cannot retieve it?
I just had that great experience again, but a little googling helped.

You need to create the hyperlink element first ('a') and append that.
this is the trick:
var aElem = document.createElement('a');

Here is a sample from:
http://acsummer.wordpress.com/2007/1...g-a-hyperlink/

function appendLink()
{
//Get the element that we want to append to
var divEl = document.getElementById('link_div');
//Create the new <a>
var aElem = document.createElement('a');
aElem.href="http://www.google.com";
//Create a text node to hold the text of the <a>
var aElemTN = document.createTextNode('link to Google.com');
//Append the <atext node to the <aelement
aElem.appendChild(aElemTN);
//Append the new link to the existing <div>
divEl.appendChild(aElem);
}
That should help. :P

Regards,
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Nov 12 '08 #5
On Nov 12, 2:16 pm, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
webmaniac schreef:
On Nov 12, 12:40 pm, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
webmaniac schreef:
>Hi,
I am creating a table dynamically in javascript.
All is fine but when I try to put any ahref link on the cell its not
taking it. I am doing like that.
var rowHead1 = document.createElement('TR');
var CellHead1 = document.createElement('TD');
var text1 = "<a href=http://www.google.com>" + someVariable + "</a>
var cellHeadText1 = document.createTextNode(text1);
CellHead1.appendChild(cellHeadText1);
But somehow when I run this example.
It shows like that in Table cell.
<a href=http://www.google.com>abc</a>
Its not converting it into a Link.
Any Idea, what's going wrong here.
Hi,
Not sure, but shouldn't you at least quote the hyperlink properly?
Like this:
var text1 = "<a href='http://www.google.com'>" + someVariable + "</a>";
Regards,
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
I tried that too, but it still dont work.
I dont know, where I am getting wrong.

Ahum, sorry.

You know this feeling you are knew how something worked but totally
cannot retieve it?
I just had that great experience again, but a little googling helped.

You need to create the hyperlink element first ('a') and append that.
this is the trick:
var aElem = document.createElement('a');

Here is a sample from:http://acsummer.wordpress.com/2007/1...ynamically-add...

function appendLink()
{
//Get the element that we want to append to
var divEl = document.getElementById('link_div');
//Create the new <a>
var aElem = document.createElement('a');
aElem.href="http://www.google.com";
//Create a text node to hold the text of the <a>
var aElemTN = document.createTextNode('link to Google.com');
//Append the <atext node to the <aelement
aElem.appendChild(aElemTN);
//Append the new link to the existing <div>
divEl.appendChild(aElem);
}

That should help. :P

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Thanks Everyone, It worked.
Nov 12 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Konrad Mathieu | last post by:
Does this work in most browsers, namely MSIE? document.links.href or does it have to be document.links.href ?
4
by: Jamie Jackson | last post by:
I know that it's possible to return false in an onClick to disable a link. Is there a way to do this within the HREF attribute? Something like: <a href="javascript: return false;"> ? Thanks,...
2
by: Ben | last post by:
Hi. I have a button that change a number of images src's when I click a button. The src's are stored in an array and I just use document.src=pics to change the src of the image. However I want...
16
by: michael | last post by:
Is it possible to get all href URLs contained in a unordered list and place them in an array? Or in fact two different arrays, differently named one for each <ul> group? <ul> <li><a...
6
by: snacktime | last post by:
I've searched and searched and have not found a solution to suppress the margin on form or href tags so that there is no space before or after the tag. The only way I have found to do this is to...
13
by: nicolas | last post by:
Hello, Somebody knows how i can simulate a click on a <A HAREF> tag ? THX Nico
4
by: Brian Watkins | last post by:
Hello All, I have a a file display page that contains two frames. In the left frame is a tree view that lists a directory and all its subfolders. Each node in the left frames tree is a link...
8
by: Alex Nitulescu | last post by:
Hi. I have the following question - is it possible (I assume it is, but I have no idea how to do it) to HIDE the href text which automatically shows in the status bar of IE ? I have build a...
1
by: nsvmani | last post by:
Hi, i am trying to get the FileOpen dialogue window as soon as clicked href link I am using IE6 with ActiveX enabled. Just need to get the File Open dialogue window when i click on the HREF links.It...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.