icklechurch
03-20-2009, 12:41 PM
Hi,
I've managed to get myself in a right pickle over getting a variable out of a table I've created using Javascript.
Basically, the table is within a basket system and works in that when you click on a row, the price in that row is set for the product price. Here is the table and preceeding Javascript:
<script type="text/javascript">
function setEvent(){
var ids = [1];
for(var j=0;j<ids.length;j++){
var rows=document.getElementById(ids[j]).getElementsByTagName('tr'), i=1, r;
while(r=rows[i++]){
i<rows.length?r.onclick=doActions:null;
}
}
function doActions(){
var rows=this.parentNode.getElementsByTagName('tr'), i=1, r, c, v;
var th=this.parentNode.parentNode.getElementsByTagName('th');
while(r=rows[i++]){
if(r==this){
r.style.backgroundColor='#ccc';
c=this.getElementsByTagName('td');
v=c[c.length-1].firstChild.data;
th[th.length-1].getElementsByTagName('p')[0].firstChild.data=v;
}
else{r.style.backgroundColor=''}
}
}
}
onload=setEvent;
</script>
<table cellpadding="3" cellspacing="1" class="basket_options_table" id="1">
<tr>
<tr>
<th>Usage</th>
<th>Resolution</th>
<th>File Size</th>
<th>Price</th>
</tr>
</tr>
<tr class="normal" onmouseover="this.className='normalon'" onmouseout="this.className='normal'" >
<td>FREE</td>
<td>320 x 288 pixels</td>
<td>size</td>
<td>£0</td>
</tr>
<tr class="normal" onmouseover="this.className='normalon'" onmouseout="this.className='normal'" >
<td>Personal Use</td>
<td>320 x 288 pixels</td>
<td>size</td>
<td>£5</td>
</tr>
<tr>
<th colspan="3"></th>
<th class="basket_record_price">
<p>£</p>
</th>
</tr>
</table>
How can I get the price out which is dynamically created in the script? I'm really confused and rather new at this so any help would be great! :)
I've managed to get myself in a right pickle over getting a variable out of a table I've created using Javascript.
Basically, the table is within a basket system and works in that when you click on a row, the price in that row is set for the product price. Here is the table and preceeding Javascript:
<script type="text/javascript">
function setEvent(){
var ids = [1];
for(var j=0;j<ids.length;j++){
var rows=document.getElementById(ids[j]).getElementsByTagName('tr'), i=1, r;
while(r=rows[i++]){
i<rows.length?r.onclick=doActions:null;
}
}
function doActions(){
var rows=this.parentNode.getElementsByTagName('tr'), i=1, r, c, v;
var th=this.parentNode.parentNode.getElementsByTagName('th');
while(r=rows[i++]){
if(r==this){
r.style.backgroundColor='#ccc';
c=this.getElementsByTagName('td');
v=c[c.length-1].firstChild.data;
th[th.length-1].getElementsByTagName('p')[0].firstChild.data=v;
}
else{r.style.backgroundColor=''}
}
}
}
onload=setEvent;
</script>
<table cellpadding="3" cellspacing="1" class="basket_options_table" id="1">
<tr>
<tr>
<th>Usage</th>
<th>Resolution</th>
<th>File Size</th>
<th>Price</th>
</tr>
</tr>
<tr class="normal" onmouseover="this.className='normalon'" onmouseout="this.className='normal'" >
<td>FREE</td>
<td>320 x 288 pixels</td>
<td>size</td>
<td>£0</td>
</tr>
<tr class="normal" onmouseover="this.className='normalon'" onmouseout="this.className='normal'" >
<td>Personal Use</td>
<td>320 x 288 pixels</td>
<td>size</td>
<td>£5</td>
</tr>
<tr>
<th colspan="3"></th>
<th class="basket_record_price">
<p>£</p>
</th>
</tr>
</table>
How can I get the price out which is dynamically created in the script? I'm really confused and rather new at this so any help would be great! :)