Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

 

Status
Not open for further replies.

greyone

Programmer
Dec 14, 2000
200
CA
i have links in a array as follows and i have a for loop which draws the table with the links. My problem is that when i see the table with the links only the link is clickable. I want the whole cell to be clickable. I know there is a very ugly way to do this and that is to use multiple   in the links. But is there any other way to do this. Please help.

<script>
var menu1=new Array()
menu1[0]='<a href=test.htm class=&quot;menu&quot;>Account Exec.</a><br>'
menu1[1]='<a href=test.htm class=&quot;menu&quot;>Employee Reps.</a><br>'
</script>


<script>
estr='<tr><td align=&quot;left&quot; class=&quot;menu&quot;>'
document.write('<table border=&quot;1&quot; width=&quot;150&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>')
for (i=0;i<menu1.length;i++)
document.write(estr+menu1+'</td></tr>')
document.write('</table>')
</script>






 
i'm not sure if this works in ns, but, <td onclick=&quot;window.location='page.htm';&quot; style=&quot;cursor:hand;&quot;>
 
but how do i do this in a loop so that i get all the links from the array. i don't want to change the structure of the code. Could you suggest some way so that this thing is possible with the code structure i had given.
 
does it have to work in NS? In IE this should work:

You'll have to change the code a bit though:

<script>
document.write('<table border=&quot;1&quot; width=&quot;150&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>')
for (i=0;i<menu1.length;i++)
estr='<tr onClick=&quot;'+menu1+'&quot;><td align=&quot;left&quot; class=&quot;menu&quot;>'
document.write(estr+menu1+'</td></tr>')
document.write('</table>')
</script>
jared@aauser.com
 
well not for the time being but yes in the future i will have to make it work n NS too. So is there a solution to it too.
 
hey but that code which you gave me dose'nt work it just displays the last element in the array with a &quot;> and also adds another cell which says undefined. Is there a solution to this
 
try this - there are two arrays - one for the actual links and one for the titles of the links:

<script>
var menutitles=new Array()
var menulinks=new Array()
menulinks[0]='test.htm'
menutitles[0]='Account Exec'
menulinks[1]='test.htm'
menutitles[1]='Employee Reps'


document.write('<table border=&quot;1&quot; width=&quot;150&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>')
for (i=0;i<menulinks.length;i++)
{
estr='<tr onClick=&quot;javascript:window.location=\''+menulinks+'\'&quot;><td align=&quot;left&quot; class=&quot;menu&quot;>'
printstr = estr+'<a href=&quot;'+menulinks+'&quot;>'+menutitles+'</a></td></tr>'
alert(printstr)
document.write(printstr)
}
document.write('</table>')
</script> jared@aauser.com
 
but i dont' want to create another array since all the links do not lead to a page. Some of them call a javascript function. So now is there anyother way. Please help
 
then in the menulinks array just do this:

menulinks[1]='javascript:callSomeFunc()'
jared@aauser.com
 
menulinks[0]='javascript:hello(&quot;thestring&quot;)'
menutitles[0]='Header'

function hello(n)
{
alert(n)
}


But something like above dosen't work.Please help
 
All right this works, but you need to make even your normal links javascript links:
<script>
var menutitles=new Array()
var menulinks=new Array()
menulinks[0]='window.location=\'test.htm\';return false'
menutitles[0]='Account Exec'
menulinks[1]='someFunc()'
menutitles[1]='Employee Reps'

function someFunc()
{
alert('jive');
}

document.write('<table border=&quot;1&quot; width=&quot;150&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>')
for (i=0;i<menulinks.length;i++)
{
estr='<tr onClick=&quot;'+menulinks+'&quot;><td align=&quot;left&quot; class=&quot;menu&quot;>'
//printstr = estr+'<a href=&quot;'+menulinks+'&quot;>'+menutitles+'</a></td></tr>'
printstr = estr+'<a href=&quot;#&quot;>'+menutitles+'</a></td></tr>'
alert(printstr)
document.write(printstr)
}
document.write('</table>')
</script> jared@aauser.com
 
Well the link works fine but as for the function it still dose'nt work since i need to pass a string as a parameter in the function .Now how do i do that. Please help
 
menulinks[1]='someFunc(\'Jive Jivenson\')' jared@aauser.com
 
hey man got it it should be something like this

menulinks[0]=&quot;hello('thestring')&quot;
 
A very clean method, using Standard HTML, for making
a table cell clickable is this:
Edit for each table cell a GIF of appropriate size, including the text.
Use this GIF as background image (one per cell).
Access to mouseclick is achieved by an image map.
Chuck Musciano: HTML...., O´Reilly.
A monochrome text on a monochrome background is a small GIF,
because of lossless LZW compression.
G.Hoffmann
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top