www.webdeveloper.com
Results 1 to 13 of 13

Thread: A bug I can't seem to find...

  1. #1
    Join Date
    Mar 2012
    Posts
    7

    A bug I can't seem to find...

    So the code this piece of the code I'm writing is pretty simple. I have empty input text boxes, and when I click the button a predetermined set of numbers appears in the textboxes. Badda Bing Badda Boom. Except, I can't seem to get them to appear -.-;; and I'm having trouble spotting the bug that could be disrupting this piece.

    Code:
    <!doctype html>
       <html>
          <head>
          <script type="text/javascript">
                  function lingrow(){
                        document.form1.input1.value=10;
                        document.form1.input2.value=20;
                        document.form1.input3.value=30;
                        document.form1.input4.value=40;
                  }
          </script>
          </head>
          <body>
                  <form name="form1">
                          Boxes of Numbers <br>
                          <input type="text" size="8" name="input1" />
                          <input type="text" size="8" name="input2" />
                          <input type="text" size="8" name="input3" />
                          <input type="text" size="8" name="input4" />
    
                          <input type="button" value="Numbers" onclick="lingrow()" />
                  </form>
          </body>
       </html>
    So here's pretty much the section that's bugging me...can't seem to find what the problem is? Am I not using the document.form1.... correctly??

  2. #2
    Join Date
    Jan 2011
    Posts
    117
    you'll need to click on the damn Numbers button first

  3. #3
    Join Date
    Mar 2012
    Posts
    7
    Well that's the problem :/ - click and no numbers co
    me up :/

  4. #4
    Join Date
    Jan 2011
    Posts
    117
    The problem is that I see all the numbers after clicking on each major browser---> what are you using or what are you testing your code on?!!

  5. #5
    Join Date
    Mar 2012
    Posts
    7
    My browser is google chrome
    And I just use a regular wordpad type thing to type up my code

  6. #6
    Join Date
    Jan 2011
    Posts
    117
    that's interesting[!] because that same code worked on mine...

  7. #7
    Join Date
    Mar 2012
    Posts
    7
    Actually i just tried it out on explorer - and it worked out fine -.-;;

    I guess my google chrome browser was acting up??

  8. #8
    Join Date
    Jan 2011
    Posts
    117
    actually I tried it in chrome first - and as said - it only needed a click and it worked

  9. #9
    Join Date
    Mar 2012
    Posts
    7

    Some additions...

    This might be a more buggy question(or perhaps not) - now I'm using Explorer (though normally I use Chrome...

    Code:
    <!doctype html>
       <html>
          <head>
          <style type="text/css">
    	     table {border-collapse:collapse;}
          </style>
          <script type="text/javascript">
     	      L=211;
                  n1=8;
                  var a1, a2, a3, a4, a5, a6, a7, a8;
    
                  function maxarr(arr,len){
                        max2= -1.0e10;
                        for (i=0; i<len; i++) 
                            if(max2 < arr[i]) 
                              max2 = arr[i];
                              return max2;
                  }
    
                  function minarr(arr1,len1){
                        max3= 1.0e10;
                        for (i=0, i<len1; i++)
                            if(max3 > arr1[i])
                              max3 = arr1[i];
                              return max3;
                  }
    
                  function lingrow(){
                        document.form1.input1.value=10;
                        document.form1.input2.value=20;
                        document.form1.input3.value=30;
                        document.form1.input4.value=40;
                  }
    
                  function expgrow(){
                        document.form1.input1.value=2;
                        document.form1.input2.value=4;
                        document.form1.input3.value=8;
                        document.form1.input4.value=16;
                  }
    
    	      function shrink(){
                        document.form1.input1.value=16;
                        document.form1.input2.value=8;
                        document.form1.input3.value=4;
                        document.form1.input4.value=2;
                  }
          </script>
          </head>
          <body>
                  <form name="form1">
                          Your Quarterly Numbers: <br>
                          <p><input type="text" size="8" name="input1" />
                          <input type="text" size="8" name="input2" />
                          <input type="text" size="8" name="input3" />
                          <input type="text" size="8" name="input4" /></p>
                          <p><input type="button" value="Linear Growth" onclick="lingrow()" />
                          <input type="button" value="Exponential Growth" onclick="expgrow()" />
    		      <input type="button" value="Shrink Reduction" onclick="shrink()" />
                  </form>
          </body>
       </html>
    So pretty much it's still adding numbers into the boxes - however, I just added another piece of code (the min and max things) that I haven't done anything with yet (though I do in need them later) and now the "no numbers" things is starting up again. So even though these min and max functions are being put to use - are they effecting my numbers appearing?

  10. #10
    Join Date
    Nov 2010
    Posts
    1,036
    compare:
    Code:
    for (i=0, i<len1; i++)
    to:
    Code:
    for (i=0; i<len1; i++)
    Produces the same result, regardless of browser (and IE actually does a pretty good job of diagnosing the problem for once)

    time to learn how to debug, methinks...

  11. #11
    Join Date
    Jan 2011
    Posts
    117
    and now the "no numbers" things is starting up again.
    That's because your function "minarr" is failing to compile ...


    This might be a more buggy question(or perhaps not) - now I'm using Explorer (though normally I use Chrome...
    Well I think you should stick to IE when debugging. You may ask "why?" - "Chrome has a better console!"
    I agree I like "chrome console" - it's the best in inspecting and testing your expressions before writing them. But when it comes to debugging IE is more useful. And has the best feedback on error reports and more precision in pinpointing them.

    Here is the Chrome error report:
    http://i39.tinypic.com/6z821w.png

    And here is Explorer report:
    http://i44.tinypic.com/1zqu68x.png

    And your actual error is here:
    Code:
                  function minarr(arr1,len1){
                        max3= 1.0e10;
                        for (i=0, i<len1; i++)  // expected ;
                            if(max3 > arr1[i])
                              max3 = arr1[i];
                              return max3;
                  }
    If corrected the page will come back to its normal working condition.

  12. #12
    Join Date
    Mar 2012
    Posts
    7
    @Troy - What editor are you using? I'm just using regular wordpad thing o.o

    Instead of creating a new thread I decided to build up on this one for pretty much the same program just more developed. So I'm having a problem for making the points and lines show up in my yellow grid table.

    Code:
    <!doctype html>
       <html>
          <head>
          <style type="text/css">
          table {border-collapse:collapse}
          </style>
          <script type="text/javascript">
                  L=211;
                  n1=8;
                  var a1, a2, a3, a4, a5, a6, a7, a8;
                 
                 function maxarr(arr,len){
                        max2= -1.0e10;
                        for (i=0; i<len; i++) 
                            if(max2 < arr[i]) 
                              max2 = arr[i];
                              return max2;
                  }
                  function minarr(arr,len){
                        max3= 1.0e10;
                        for (i=0; i<len; i++)
                            if(max3 > arr[i])
                              max3 = arr[i];
                              return max3;
                  }
                  function lingrow(){
                        document.form1.input1.value=10;
                        document.form1.input2.value=20;
                        document.form1.input3.value=30;
                        document.form1.input4.value=40;
                        document.form1.input5.value="";
                        document.form1.input6.value="";
                        document.form1.input7.value="";
                        document.form1.input8.value="";
                        document.form1.analysis.value="";
                  }
                  function expgrow(){
                        document.form1.input1.value=2;
                        document.form1.input2.value=4;
                        document.form1.input3.value=8;
                        document.form1.input4.value=16;
                        document.form1.input5.value="";
                        document.form1.input6.value="";
                        document.form1.input7.value="";
                        document.form1.input8.value="";
                        document.form1.analysis.value="";
                  }
                  function shrink(){
                        document.form1.input1.value=256;
                        document.form1.input2.value=128;
                        document.form1.input3.value=64;
                        document.form1.input4.value=32;
                        document.form1.input5.value="";
                        document.form1.input6.value="";
                        document.form1.input7.value="";
                        document.form1.input8.value="";
                        document.form1.analysis.value="";
                  }
                  function forecast(){
                        a1=parseFloat(document.form1.input1.value);
                        a2=parseFloat(document.form1.input2.value);
                        a3=parseFloat(document.form1.input3.value);
                        a4=parseFloat(document.form1.input4.value);
    
                        c1=a2-a1;
                        c2=a3-a2;
                        c3=a4-a3;
                        cmax=Math.max(Math.abs(c1), Math.abs(c2), Math.abs(c3));
                        cmin=Math.min(Math.abs(c1), Math.abs(c2), Math.abs(c3));
                        err=cmax-cmin;
                        avga=(a1+a2+a3+a4)/4;
                        erra=err/avga;
                        avgc=(c1+c2+c3)/3;
    
                        e1=a2/a1;
                        e2=a3/a2;
                        e3=a4/a3;
                        emax=Math.max(e1,e2,e3);
                        emin=Math.min(e1,e2,e3);
                        errg=emax-emin;
                        avge=(e1+e2+e3)/3;
    
                        if(errg>erra)stype="A";
                           else stype="G";
    
                        if(stype=="A"){
                           a5=a4+avgc;
                           a6=a5+avgc;
                           a7=a6+avgc;
                           a8=a7+avgc;
                        }
                        else{
                           a5=a4*avge;
                           a6=a5*avge;
                           a7=a6*avge;
                           a8=a7*avge;
                        }
                        document.form1.input5.value=a5.toFixed(2);
                        document.form1.input6.value=a6.toFixed(2);
                        document.form1.input7.value=a7.toFixed(2);
                        document.form1.input8.value=a8.toFixed(2);
    
                        msglin='Your data is more like a linear trend than a % growth. ';
                        msglin= msglin+'The average change per period is '+avgc+'%';
                        msgexpgr='Your data is more like an exponential growth. ';
                        avgrgr=100.*(avge-1.0); 
                        avgrgr=avgrgr.toFixed(2);
                        msgexpgr=msgexpgr+'The average growth per period is '+avgrgr+'%';
                        msgshrink='Your data is more like a shrink reduction. ';
                        avgrred=100.*(1.0-avge); 
                        avgrred=avgrred.toFixed(2);
                        msgshrink=msgshrink+'The average reduction per period is '+avgrred+'%';
                 
                        if(stype=="A")document.form1.analysis.value=msglin;
                           else if(avge>1.0) document.form1.analysis.value=msgexpgr;
                                   else document.form1.analysis.value=msgshrink;
                  } 
    		
                  function point(xm,ym,colorp){
                        ym=Math.round(ym);
                        xm=Math.round(xm);
                        id=(L-ym+1)+","+xm;
                        cell1=document.getElementById(id);
                        cell1.style.backgroundColor=colorp;
                  }
    
                  function points(xm,ym,colorp,n){
                        n2=Math.floor(n/2);
                        for(i1=0;i1<n;i1++)
                           for(j1=0; j1<n; j1++)
                              point(xm-n2+i1, ym-n2+ji, colorp);
                  }
    
                  function line1(xm,ym,xn,yn,colorp){
                        m=(yn-ym)*1/(xn-xm);
                        if(Math.abs(xn-xm) >= Math.abs(yn-ym)){
    	               for(j=xm;j<=xn;j++){
                               y=m*(j-xm)+ym;
                               point(j,y,colorp);
                           }
                        }
                        else{
                           ymax=Math.max(ym,yn);
                           ymin=Math.min(ym,yn);
                           for(i1=ymin;i1<=ymax;i1++){
                               x=(i1-ym)/m+xm;
                               point(x,i1,colorp);
                           }
                        }
                  }
                  
                  function plot(){
                        xs1=new Array();
                        ys1=new Array(a1,a2,a3,a4,a5,a6,a7,a8);
                        ys2=new Array();
                        max1=maxray(ys1,n1);
                        min1=minray(ys1,n1);
    
                        for(i=0;i<n1;i++)
                           ys2[i]=(ys1[i]-min1)/(max1-min1)*(L-20)+10;
                        for(i=0;i<n1;i++)
                           xs1[i]=Math.round((L-20)/(n1-1)*i+10);
                        for(i=0;i<n1/2;i++){
                           line1(xs1[i],ys2[i],xs1[i+1],ys2[i+1], "brown");
                           points(xs1[i],ys2[i],"brown",3);
                        }
                        for(i=n1/2;i<n1;i++){
                           if(i!=n1-1)
                             line1(xs1[i],ys2[i],xs1[i+1],ys2[i+1],"blue");
                             points(xs1[i],ys2[i],"blue",3);
                        }
                  }
          </script>
          </head>
          <body>
                  <form name="form1">
                          Your Quarterly Numbers: <br>
                          <p><input type="text" size="8" name="input1" />
                          <input type="text" size="8" name="input2" />
                          <input type="text" size="8" name="input3" />
                          <input type="text" size="8" name="input4" />
                          <p><input type="button" value="Linear Growth" onclick="lingrow()" />
                          <input type="button" value="Exponential Growth" onclick="expgrow()" />
                          <input type="button" value="Shrink Reduction" onclick="shrink()" />
                   <p>Projected Future Forecast: <br>
                          <p><input type="text" size="8" name="input5" />
                          <input type="text" size="8" name="input6" />
                          <input type="text" size="8" name="input7" />
                          <input type="text" size="8" name="input8" />
                          <p><input type="text" size="115" name="analysis" />
                          <p><input type="button" value="Forecast" onclick="forecast()" />
                          <p>Plotting of Data:<br>
                          <p><input type="button" value="Plot" onclick="plot()" />
                          <input type="button" value="Clear plot" onclick="clearplot()" />
                  </form>
                  <table>
                  <script>
                         wx=500;
                         wy=600;
                         dx=Math.floor(wx/L);
                         dy=Math.floor(wy/L);
                         for(i=0;i<L;i++){
                            document.write("<tr>");
                               for(j=0;j<L;j++){
                                  color="yellow";
                                  id=j+","+i;
                                  document.write("<td id="+id+" style='background-color:"+color+";width:"+dx+";height:"+dy+"'></td>");
                               }
                         document.write("</tr>");
                         }
                  </script>
                  </table>
          </body>
       </html>

  13. #13
    Join Date
    Jan 2011
    Posts
    117
    Quote Originally Posted by Harlequinade View Post
    @Troy - What editor are you using? I'm just using regular wordpad thing o.o

    Instead of creating a new thread I decided to build up on this one for pretty much the same program just more developed. So I'm having a problem for making the points and lines show up in my yellow grid table.

    Code:
    <!doctype html>
       <html>
          <head>
          <style type="text/css">
          table {border-collapse:collapse}
          </style>
          <script type="text/javascript">
                  L=211;
                  n1=8;
                  var a1, a2, a3, a4, a5, a6, a7, a8;
                 
                 function maxarr(arr,len){
                        max2= -1.0e10;
                        for (i=0; i<len; i++) 
                            if(max2 < arr[i]) 
                              max2 = arr[i];
                              return max2;
                  }
                  function minarr(arr,len){
                        max3= 1.0e10;
                        for (i=0; i<len; i++)
                            if(max3 > arr[i])
                              max3 = arr[i];
                              return max3;
                  }
                  function lingrow(){
                        document.form1.input1.value=10;
                        document.form1.input2.value=20;
                        document.form1.input3.value=30;
                        document.form1.input4.value=40;
                        document.form1.input5.value="";
                        document.form1.input6.value="";
                        document.form1.input7.value="";
                        document.form1.input8.value="";
                        document.form1.analysis.value="";
                  }
                  function expgrow(){
                        document.form1.input1.value=2;
                        document.form1.input2.value=4;
                        document.form1.input3.value=8;
                        document.form1.input4.value=16;
                        document.form1.input5.value="";
                        document.form1.input6.value="";
                        document.form1.input7.value="";
                        document.form1.input8.value="";
                        document.form1.analysis.value="";
                  }
                  function shrink(){
                        document.form1.input1.value=256;
                        document.form1.input2.value=128;
                        document.form1.input3.value=64;
                        document.form1.input4.value=32;
                        document.form1.input5.value="";
                        document.form1.input6.value="";
                        document.form1.input7.value="";
                        document.form1.input8.value="";
                        document.form1.analysis.value="";
                  }
                  function forecast(){
                        a1=parseFloat(document.form1.input1.value);
                        a2=parseFloat(document.form1.input2.value);
                        a3=parseFloat(document.form1.input3.value);
                        a4=parseFloat(document.form1.input4.value);
    
                        c1=a2-a1;
                        c2=a3-a2;
                        c3=a4-a3;
                        cmax=Math.max(Math.abs(c1), Math.abs(c2), Math.abs(c3));
                        cmin=Math.min(Math.abs(c1), Math.abs(c2), Math.abs(c3));
                        err=cmax-cmin;
                        avga=(a1+a2+a3+a4)/4;
                        erra=err/avga;
                        avgc=(c1+c2+c3)/3;
    
                        e1=a2/a1;
                        e2=a3/a2;
                        e3=a4/a3;
                        emax=Math.max(e1,e2,e3);
                        emin=Math.min(e1,e2,e3);
                        errg=emax-emin;
                        avge=(e1+e2+e3)/3;
    
                        if(errg>erra)stype="A";
                           else stype="G";
    
                        if(stype=="A"){
                           a5=a4+avgc;
                           a6=a5+avgc;
                           a7=a6+avgc;
                           a8=a7+avgc;
                        }
                        else{
                           a5=a4*avge;
                           a6=a5*avge;
                           a7=a6*avge;
                           a8=a7*avge;
                        }
                        document.form1.input5.value=a5.toFixed(2);
                        document.form1.input6.value=a6.toFixed(2);
                        document.form1.input7.value=a7.toFixed(2);
                        document.form1.input8.value=a8.toFixed(2);
    
                        msglin='Your data is more like a linear trend than a &#37; growth. ';
                        msglin= msglin+'The average change per period is '+avgc+'%';
                        msgexpgr='Your data is more like an exponential growth. ';
                        avgrgr=100.*(avge-1.0); 
                        avgrgr=avgrgr.toFixed(2);
                        msgexpgr=msgexpgr+'The average growth per period is '+avgrgr+'%';
                        msgshrink='Your data is more like a shrink reduction. ';
                        avgrred=100.*(1.0-avge); 
                        avgrred=avgrred.toFixed(2);
                        msgshrink=msgshrink+'The average reduction per period is '+avgrred+'%';
                 
                        if(stype=="A")document.form1.analysis.value=msglin;
                           else if(avge>1.0) document.form1.analysis.value=msgexpgr;
                                   else document.form1.analysis.value=msgshrink;
                  } 
    		
                  function point(xm,ym,colorp){
                        ym=Math.round(ym);
                        xm=Math.round(xm);
                        id=(L-ym+1)+","+xm;
                        cell1=document.getElementById(id);
                        cell1.style.backgroundColor=colorp;
                  }
    
                  function points(xm,ym,colorp,n){
                        n2=Math.floor(n/2);
                        for(i1=0;i1<n;i1++)
                           for(j1=0; j1<n; j1++)
                              point(xm-n2+i1, ym-n2+ji, colorp);
                  }
    
                  function line1(xm,ym,xn,yn,colorp){
                        m=(yn-ym)*1/(xn-xm);
                        if(Math.abs(xn-xm) >= Math.abs(yn-ym)){
    	               for(j=xm;j<=xn;j++){
                               y=m*(j-xm)+ym;
                               point(j,y,colorp);
                           }
                        }
                        else{
                           ymax=Math.max(ym,yn);
                           ymin=Math.min(ym,yn);
                           for(i1=ymin;i1<=ymax;i1++){
                               x=(i1-ym)/m+xm;
                               point(x,i1,colorp);
                           }
                        }
                  }
                  
                  function plot(){
                        xs1=new Array();
                        ys1=new Array(a1,a2,a3,a4,a5,a6,a7,a8);
                        ys2=new Array();
                        max1=maxray(ys1,n1);
                        min1=minray(ys1,n1);
    
                        for(i=0;i<n1;i++)
                           ys2[i]=(ys1[i]-min1)/(max1-min1)*(L-20)+10;
                        for(i=0;i<n1;i++)
                           xs1[i]=Math.round((L-20)/(n1-1)*i+10);
                        for(i=0;i<n1/2;i++){
                           line1(xs1[i],ys2[i],xs1[i+1],ys2[i+1], "brown");
                           points(xs1[i],ys2[i],"brown",3);
                        }
                        for(i=n1/2;i<n1;i++){
                           if(i!=n1-1)
                             line1(xs1[i],ys2[i],xs1[i+1],ys2[i+1],"blue");
                             points(xs1[i],ys2[i],"blue",3);
                        }
                  }
          </script>
          </head>
          <body>
                  <form name="form1">
                          Your Quarterly Numbers: <br>
                          <p><input type="text" size="8" name="input1" />
                          <input type="text" size="8" name="input2" />
                          <input type="text" size="8" name="input3" />
                          <input type="text" size="8" name="input4" />
                          <p><input type="button" value="Linear Growth" onclick="lingrow()" />
                          <input type="button" value="Exponential Growth" onclick="expgrow()" />
                          <input type="button" value="Shrink Reduction" onclick="shrink()" />
                   <p>Projected Future Forecast: <br>
                          <p><input type="text" size="8" name="input5" />
                          <input type="text" size="8" name="input6" />
                          <input type="text" size="8" name="input7" />
                          <input type="text" size="8" name="input8" />
                          <p><input type="text" size="115" name="analysis" />
                          <p><input type="button" value="Forecast" onclick="forecast()" />
                          <p>Plotting of Data:<br>
                          <p><input type="button" value="Plot" onclick="plot()" />
                          <input type="button" value="Clear plot" onclick="clearplot()" />
                  </form>
                  <table>
                  <script>
                         wx=500;
                         wy=600;
                         dx=Math.floor(wx/L);
                         dy=Math.floor(wy/L);
                         for(i=0;i<L;i++){
                            document.write("<tr>");
                               for(j=0;j<L;j++){
                                  color="yellow";
                                  id=j+","+i;
                                  document.write("<td id="+id+" style='background-color:"+color+";width:"+dx+";height:"+dy+"'></td>");
                               }
                         document.write("</tr>");
                         }
                  </script>
                  </table>
          </body>
       </html>
    I use the default right-click view source from Explorer when editing which means I'm using Notepad. As, and since forever. Its easier ...
    ***
    I'll have to see into this code and try to understand your question from it than...

    ***
    ?OK, to start with lines:

    max1=maxray(ys1,n1);
    min1=minray(ys1,n1);


    maxray(); and minray(); do not exist
    Last edited by Troy III; 04-26-2012 at 12:53 PM.

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