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!

Is JavaScript this dynamic?

Status
Not open for further replies.

taval

Programmer
Jul 19, 2000
192
GB
I have a table with a list of numbers down which are entered in using asp, like

days
132
676
768
678
680

I was wondering is it possible using JavaScript to change the numbers in the whole column e.g dividing all the numbers of days by 7 to get weeks by clicking on a link or button without the page having to actual reload again.

Grateful for any help, Thanks.

Taha
[sig][/sig]
 
Taha,

Using the Document Object Model this can be accomplished. The code below is IE specific but could be made to work with NN as well...

Code:
<html>
<head>
<script>
 function fnConvertDaysToWeeks(numRows){
  var currentRow = 0;
  var numDaysInWeek = 7;
  
  for (i=1;i<=numRows;i++){
   currentRow = eval(&quot;tr&quot; + i + &quot;.innerText&quot;);
   currentRow = parseInt(currentRow)
   currentRow = parseInt(currentRow/numDaysInWeek);
   eval(&quot;tr&quot; + i + &quot;.innerText=currentRow&quot;); 
  }
 }
</script>
</head>
<body>
 <table>
  <tr id=trTitle><td><a href=&quot;javascript:fnConvertDaysToWeeks(5)&quot;>Days</a></td></tr>
  <tr><td id=tr1>132</td></tr>
  <tr><td id=tr2>676</td></tr>
  <tr><td id=tr3>768</td></tr>
  <tr><td id=tr4>678</td></tr>
  <tr><td id=tr5>680</td></tr>
</body>
</html>

You would, of course, need to have your asp generate the table and fill in on the function call then number of rows to process and give each td a sequential id.

Hope this helps,
Rob [sig][/sig]
 
Thanks, it'll may take my browser a couple of seconds to process that but for me it'll take a bit longer. I think I have an idea of how I can do it now, I'll give it a try and get back to you.

Thanks again.
P.S Where do you find the time to help saps like me? :} [sig][/sig]
 
LOL , My main job function is writing programs and doing dev work. While rebuilding my dev box (which happens a lot and takes about 45 minutes to ghost) I have time to help others. Its not so philanthropic as it sounds as this helps me keep my skills sharp.

Rob [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top