HighDots Forums  

Dynamically Creating Tables that Include Cell's with URL's

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss Dynamically Creating Tables that Include Cell's with URL's in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
BenignVanilla
 
Posts: n/a

Default Dynamically Creating Tables that Include Cell's with URL's - 04-27-2006 , 01:48 PM






I am dynamically building a table from data, and have run into a problem. I
have numerous rows and cells that are being created just fine, similar to
this:

tdElem = document.createElement("td");
tdElem.className = "approved_date";
txtNode = document.createTextNode($rs('approved_date'));
tdElem.appendChild(txtNode);
trElem.appendChild(tdElem);

However, when I try create a TextNode with a URL in it, I cannot get the
escape sequence right to show the URL, similar to this:

tdElem = document.createElement("td");
tdElem.className = "row_actions";
tdElem.align= "center";
txtNode = document.createTextNode("\<a href=" + "\"" +
"javascript:EditLineItem()" + "\"" + ">Edit</a> | Delete");
tdElem.appendChild(txtNode);
trElem.appendChild(tdElem);

Is there some way to include a URL in a dynamically created textnode?

BV.



Reply With Quote
  #2  
Old   
BenignVanilla
 
Posts: n/a

Default Re: Dynamically Creating Tables that Include Cell's with URL's - 04-27-2006 , 02:10 PM







"BenignVanilla" <bvanilla (AT) tibetanbeefgarden (DOT) com> wrote

Quote:
I am dynamically building a table from data, and have run into a problem. I
have numerous rows and cells that are being created just fine, similar to
this:
snip
However, when I try create a TextNode with a URL in it, I cannot get the
escape sequence right to show the URL, similar to this:
snip
Is there some way to include a URL in a dynamically created textnode?
I found an answer. Wayne Dobson responded to another thread on a slightly
different issue, and I was able to
alter my code to match his response to fix my problem...

Try:

function createHREF(text,href)
{
var a = document.createElement("A")
document.body.appendChild(a)
var t = document.createTextNode()
t.data = text
a.href = href
a.onmouseover = gotoHREF
a.appendChild(t)
a.appendChild(document.createElement("BR"))
return a
}

function gotoHREF()
{
window.open(this.href) // Opens a new window.
//window.location = this.href
//Above opens in same window.
}

var hrefs = [ ["Yahoo","http://www.yahoo.co.uk"],
["Hotmail","http://www.hotmail.co.uk"] ]

for( var i = 0 ; i < hrefs.length ; i++ )
createHREF(hrefs[i][0],hrefs[i][1])





Reply With Quote
  #3  
Old   
Jochen Wilhelm
 
Posts: n/a

Default Re: Dynamically Creating Tables that Include Cell's with URL's - 04-27-2006 , 02:55 PM



BenignVanilla wrote:

Quote:
I am dynamically building a table from data, and have run into a problem.
I have numerous rows and cells that are being created just fine, similar
to this:

tdElem = document.createElement("td");
tdElem.className = "approved_date";
txtNode = document.createTextNode($rs('approved_date'));
tdElem.appendChild(txtNode);
trElem.appendChild(tdElem);

However, when I try create a TextNode with a URL in it, I cannot get the
escape sequence right to show the URL, similar to this:

tdElem = document.createElement("td");
tdElem.className = "row_actions";
tdElem.align= "center";
txtNode = document.createTextNode("\<a href=" + "\"" +
"javascript:EditLineItem()" + "\"" + ">Edit</a> | Delete");
tdElem.appendChild(txtNode);
trElem.appendChild(tdElem);

Is there some way to include a URL in a dynamically created textnode?

BV.

Hi,
did you tried the following:

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

link.href = "javascript:EditLineItem()";
var linkdesr = document.createTextNode("Edit");
var delete = document.createTextNode("| Delete");

link.appendChild(linkdescr);



tdElement.appendChild(link);
tdElement.appendChild(delete);
--
Didn't tried this solution so far, but should work.

Good luck ;-)


Regards

Jochen


Reply With Quote
  #4  
Old   
Wayne Dobson
 
Posts: n/a

Default Re: Dynamically Creating Tables that Include Cell's with URL's - 04-28-2006 , 01:24 PM




"BenignVanilla" <bvanilla (AT) tibetanbeefgarden (DOT) com> wrote

Quote:
"BenignVanilla" <bvanilla (AT) tibetanbeefgarden (DOT) com> wrote in message
news:tt-dnYI2t-YAmczZnZ2dnUVZ_sednZ2d (AT) giganews (DOT) com...
I am dynamically building a table from data, and have run into a problem.
I
have numerous rows and cells that are being created just fine, similar to
this:
snip
However, when I try create a TextNode with a URL in it, I cannot get the
escape sequence right to show the URL, similar to this:
snip
Is there some way to include a URL in a dynamically created textnode?

I found an answer. Wayne Dobson responded to another thread on a slightly
different issue, and I was able to
alter my code to match his response to fix my problem...

Try:

function createHREF(text,href)
{
var a = document.createElement("A")
document.body.appendChild(a)
var t = document.createTextNode()
t.data = text
a.href = href
a.onmouseover = gotoHREF
a.appendChild(t)
a.appendChild(document.createElement("BR"))
return a
}
I think it was a little long-winded. This would be more concise:

var a = document.createElement("A")
a.href = href
a.appendChild(document.createTextNode(text))
document.body.appendChild(a)
document.body.appendChild(document.createElement(" BR"))
return a

That's without a mouseover effect.
--
Wayne
"Aka Dobbie the House Elf."




Reply With Quote
  #5  
Old   
BenignVanilla
 
Posts: n/a

Default Re: Dynamically Creating Tables that Include Cell's with URL's - 05-04-2006 , 09:03 AM




"Wayne Dobson" <nospam (AT) noaddress (DOT) com> wrote

Quote:
"BenignVanilla" <bvanilla (AT) tibetanbeefgarden (DOT) com> wrote in message
news:2N2dnfr8TvcllMzZnZ2dnUVZ_sydnZ2d (AT) giganews (DOT) com...

"BenignVanilla" <bvanilla (AT) tibetanbeefgarden (DOT) com> wrote in message
news:tt-dnYI2t-YAmczZnZ2dnUVZ_sednZ2d (AT) giganews (DOT) com...
I am dynamically building a table from data, and have run into a
problem.
I
have numerous rows and cells that are being created just fine, similar
to
this:
snip
However, when I try create a TextNode with a URL in it, I cannot get
the
escape sequence right to show the URL, similar to this:
snip
Is there some way to include a URL in a dynamically created textnode?

I found an answer. Wayne Dobson responded to another thread on a slightly
different issue, and I was able to
alter my code to match his response to fix my problem...

Try:

function createHREF(text,href)
{
var a = document.createElement("A")
document.body.appendChild(a)
var t = document.createTextNode()
t.data = text
a.href = href
a.onmouseover = gotoHREF
a.appendChild(t)
a.appendChild(document.createElement("BR"))
return a
}

I think it was a little long-winded. This would be more concise:

var a = document.createElement("A")
a.href = href
a.appendChild(document.createTextNode(text))
document.body.appendChild(a)
document.body.appendChild(document.createElement(" BR"))
return a

That's without a mouseover effect.
My issue was a bit different, but using your example, I was able to solve my
issue, so I am very grateful!!

BV.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.