newbie...need help

S

shotokan99

i made a table dynamically :
..
..
..
</style>
</head>
<body>
<div id="dmain" align="center" class="normaltxt">
<table align="center" border="1">
<script type="text/javascript">
artist=new Array();
artist[0]='James';
artist[1]='Lea';
artist[2]='Rudy';
artist[3]='Wonder 9';
artist[4]='Arthur';
artist[5]='Dave';
artist[6]='Fred';
artist[7]='Howard';
artist[8]='Cindy';

James=new Array();
James[0]='Do you know';
James[1]='Your song';
James[2]='Im coming home';

row=3;
col=3;
a=0;
for(i=1; i<=row; i++){
document.write('<tr>');
for(n=1; n<=col; n++){
document.write('<td width="200" height="30"
onclick="dispsong('+artist[a]+')">'
+artist[a]+'</td>');
a=a+1;
}
document.write('</tr>');
}
</script>
..
..
..

what should happen is whenever the user clicks on the artist it must
display another table containing his/ her songs. what i wanted to
happen is the table be displayed underneath the artist table. but what
is happening now, upon clicking the page refreshes and display on the
song table. what is the work around for this?


<script type="text/javascript">
function dispsong(s){
_col=3;
_row=Math.round(s.length/3);
x=0;
document.write('<table align="center" border="1" >');
for(i=1;i<=_row; i++){
document.write('<tr>');
for(n=1; n<=_col; n++){
document.write('<td width="200" height="30" class="normaltxt">'+s[x]
+'</td>');
x=x+1;
}
document.write('</tr>');
}
document.write('</table>');
}
</script>
 
P

Peter Michaux

i made a table dynamically :
.
.
.
</style>
</head>
<body>
<div id="dmain" align="center" class="normaltxt">
<table align="center" border="1">
<script type="text/javascript">
artist=new Array();
artist[0]='James';
artist[1]='Lea';
artist[2]='Rudy';
artist[3]='Wonder 9';
artist[4]='Arthur';
artist[5]='Dave';
artist[6]='Fred';
artist[7]='Howard';
artist[8]='Cindy';

James=new Array();
James[0]='Do you know';
James[1]='Your song';
James[2]='Im coming home';

row=3;
col=3;
a=0;
for(i=1; i<=row; i++){
document.write('<tr>');
for(n=1; n<=col; n++){
document.write('<td width="200" height="30"
onclick="dispsong('+artist[a]+')">'
+artist[a]+'</td>');
a=a+1;
}
document.write('</tr>');}

</script>
.
.
.

what should happen is whenever the user clicks on the artist it must
display another table containing his/ her songs. what i wanted to
happen is the table be displayed underneath the artist table. but what
is happening now, upon clicking the page refreshes and display on the
song table. what is the work around for this?

<script type="text/javascript">
function dispsong(s){
_col=3;
_row=Math.round(s.length/3);
x=0;
document.write('<table align="center" border="1" >');
for(i=1;i<=_row; i++){
document.write('<tr>');
for(n=1; n<=_col; n++){
document.write('<td width="200" height="30" class="normaltxt">'+s[x]
+'</td>');
x=x+1;
}
document.write('</tr>');
}
document.write('</table>');}

</script>

You don't want to use document.write here. Generally speaking,
document.write is used when the page is being parsed and built when
the page loads. If you want to dynamically generate elements after the
page has been completely built you want to use document.createElement
and related DOM functions. David Flanagan's book "JavaScript the
definitive guide" from O'Reilly is a good reference for this activity.


Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,883
Members
47,415
Latest member
SharonCran

Latest Threads

Top