www.webdeveloper.com
Results 1 to 3 of 3

Thread: Save new highest records compare with old calculation value

  1. #1
    Join Date
    Apr 2010
    Posts
    18

    Post Save new highest records compare with old calculation value

    i am generating 3 values randomly and calculate bigger one from 3.

    calculate bigger diff with compare with big random value which i created.

    so the final calculated value in row 3 is changing all time.

    now i want to record highest/maximum diff value set fixed in row 4

    my code here:

    Code:
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    <script type="text/javascript">
    <!--
    
    var timerSeed;
    var timer;
     
    function processData() {
    var R = parseInt(document.getElementById("P3:0:0").innerHTML);
    var S = parseInt(document.getElementById("P3:1:0").innerHTML);
    var T = parseInt(document.getElementById("P3:2:0").innerHTML);
     
    //find the max of RST
    var maxPhase = Math.max(R,S,T);
    document.getElementById("maxVolts").innerHTML = maxPhase;
     
    //subract the other 2 voltages from the max
    var RR = Math.abs(maxPhase-R);
    var RS = Math.abs(maxPhase-S);
    var RT = Math.abs(maxPhase-T);
    
    var diff = Math.max(RR,RS,RT);
    document.getElementById("maxVolts2").innerHTML=diff;
    
    
    
    
    /***********Maximum diff records in field compare with new diff*******/
    var newv =  diff; 
    var oldv = 0;
     if (newv > oldv) { oldv = newv ;}
     else { oldv = oldv ; }
    
    document.getElementById("saj1").innerText = oldv;
    
    }
     
    //this function simulates changing voltages via a setInterval()
    function setNewVoltages() {
    document.getElementById("P3:0:0").innerHTML = parseInt(document.getElementById("P3:0:0").innerHTML) + Math.round(Math.random()+2);
    document.getElementById("P3:1:0").innerHTML = parseInt(document.getElementById("P3:1:0").innerHTML) + Math.round(Math.random()+2);
    document.getElementById("P3:2:0").innerHTML = parseInt(document.getElementById("P3:2:0").innerHTML) + Math.round(Math.random()+2);
    }
     
    //-->
    </script>
    </head> <center>
    <body onload="timer=setInterval('processData()',1000); timerSeed=setInterval('setNewVoltages()',2000)">
     
    <div><center>
    <table>
    <tr>
     <td class="inner" align="left">
      <div class="value" id="P3:0:0">10</div>
        </td> <td> </td> <td> </td> <td> </td><td> </td> <td> </td> <td> </td><td> </td> <td> </td> <td> </td>
     <td class="inner" align="left">
         <div class="value" id="P3:1:0">13</div>
        </td><td> </td> <td> </td> <td> </td><td> </td> <td> </td> <td> </td><td> </td> <td> </td> <td> </td>
     <td class="inner" align="left">
         <div class="value" id="P3:2:0">15</div>
       </td>
    </tr>
    </table>
    <br /> <br />
    </div>
     
    <div>
    <span>Bigger value= </span><span id="maxVolts"></span>    
    </div>
     <br /><br />
    <div>
    <span>Difference  = </span><span id="maxVolts2"></span></div> 
    <br /><br />
    
     <div><span>Max  diff record =   </span><span id="saj1"></span> </div>
    
    
     
    </body>
    </html>
    but i am facing problem in the output row 4 is not showing calculated result which must be calculate continuously after each 1 sec with compare with output row 3 and show the highest result in row 4 .

    all coding are working well with out this row 4 code
    Code:
    var newv =  diff; 
    var oldv = 0;
     if (newv > oldv) { oldv = newv ;}
     else { oldv = oldv ; }
    
    document.getElementById("saj1").innerText = oldv;
    i also tried this way but not working

    Code:
    var newv =  diff;
    var oldv = newv ;    // i set it 0 or newv, but not working
    
    var oldv1 = Math.max(newv,oldv); 
    
    document.getElementById("saj1").innerText = oldv1;
    What change i need here specially for output row 4 result...
    Last edited by sajib0189; 10-11-2012 at 03:34 PM.

  2. #2
    Join Date
    Nov 2006
    Location
    Oakland
    Posts
    500
    Have you confirmed that the value of "diff" you get is numeric?
    You can just use your web browser's console to see the error messages as well as the line where the error occurred.

  3. #3
    Join Date
    Apr 2010
    Posts
    18
    Quote Originally Posted by holyhttp View Post
    Have you confirmed that the value of "diff" you get is numeric?
    You can just use your web browser's console to see the error messages as well as the line where the error occurred.
    yes, after your reply i open it in iE, its coming in IE ...that means code is ok.
    but problem is row 4 "Max diff record =" is going up if row 3 "difference" is going up,but if row 3 "difference" go down row 4 results also go down.i want row 4 increase if row 3 results increase but its stay the previous result if row 3 results go down.

    that means i think, else {} not working or var oldv = 0; needs to define again...am i right?

    Code:
    var newv =  diff; 
    var oldv = 0;
     if (newv > oldv) { oldv = newv ;}
     else { oldv = oldv ; }
    document.getElementById("saj1").innerText = oldv;
    from my main code if i change the little code like this, row 3 sometimes go up and sometimes down
    Code:
    function setNewVoltages() {
    document.getElementById("P3:0:0").innerHTML = parseInt(document.getElementById("P3:0:0").innerHTML) + Math.round(Math.random()-2);
    document.getElementById("P3:1:0").innerHTML = parseInt(document.getElementById("P3:1:0").innerHTML) + Math.round(Math.random()-2);
    document.getElementById("P3:2:0").innerHTML = parseInt(document.getElementById("P3:2:0").innerHTML) + Math.round(Math.random()-2);
    }
    example: what i need :
    if Difference = 3, Max diff record = 3.
    if Difference = 5, Max diff record = 5. [if 1st one increase, 2nd one also increase. compare to previous 3(row 1 2nd result ) and 5(row 2 (1st) ]
    if Difference = 2, Max diff record = 5. [needs to show previous one compare 5(row 2 2nd result ) and 2( row 3,1st result) ]
    if Difference = 1, Max diff record = 5. [needs to show previous one compare 5 and 1]
    Last edited by sajib0189; 10-12-2012 at 02:32 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles