operators - Javascript: if (x < y) works, if(x<=y) does not work. -


if (x < y) works, if(x<=y) not work in javascript. in former case if-statement evaluated, in later case if-staement ignored.

here's code:

var totalframes = 12; 

here showvalue functiion receives value html:

<input type="range" min="2" max="36" step="2" value="2" name="totalframes"        onchange="showvalue(this.value);" width: 80%" value="2"/> <p>total frames: <span id="totalframes">2</span>    function showvalue(newvalue) {          document.getelementbyid("totalframes").innerhtml = parsefloat(newvalue);          totalframes = parseint(newvalue);          var winkel = 360.0/totalframes;          document.getelementbyid("angle").innerhtml = winkel.tofixed(1);          var maxframe = document.getelementsbyname("actframe")[0];          maxframe.max = parseint(newvalue); }  function motorcommunication() {        actframe = document.getelementbyid("actframe").value;       actualframe = parseint(document.getelementbyid("actframe").value);       document.getelementbyid("range").innerhtml = actframe;  

/* line work -- if statement not ignored*/

if ( number(actualframe) < number(totalframes) ) {  

/* line not work -- if statement ignored*/

if ( number(actualframe) <= number(totalframes) ) {       var url = "/cgi-bin/bn_events.py?actualframe=" + escape(actualframe)           + "&totalframes=" + escape(totalframes)           + "&seconds=" + escape(seconds);      request.open("get", url, true);      request.onreadystatechange = updatepage;      request.send(null);      actualframe++;   }   else {        document.getelementbyid("returnedstatus").value = "done.";   } }  function updatepage() {   if (request.readystate == 4) {     if (request.status == 200) {       /* response server */       var motorresponse = request.responsetext;       motordata = new array();       //motordata = request.responsetext;       motordata = motorresponse.substring(0,motorresponse.length-1).split(",");       /* update html web form */       document.getelementbyid("returnedframe").value = motordata[0];       document.getelementbyid("returnedtotalframes").value = motordata[1]       document.getelementbyid("returnedstatus").value = motordata[2];       document.getelementbyid("actframe").value = parseint(actualframe);       document.getelementbyid("actualstatus").value = parseint(actualframe);            settimeout(motorcommunication(),300);       } else {       alert("error! request status " + request.status);       }     } } 

what found out is, if use

if ( number(actualframe) <= 12 ) { 

it works perfectly....

helpless now... appreciate comment.

got fixed... had nothing str int or similar... if-statement on wrong position. variables screwed up.

function motorcommunication() {          /* needs here... */          if ( actualframe <= lastframe * 1.0 ) {          actframe = document.getelementbyid("actframe").value;          actualframe = parseint(document.getelementbyid("actframe").value);          document.getelementbyid("range").innerhtml = actframe * 1.0;            //lastframe = parseint(document.getelementsbyname("totalframes")[0].value);           document.getelementbyid("returnedtotalframes").value = lastframe * 1.0;          //wrong here: if ( actualframe <= lastframe * 1.0 ) {             var url = "/cgi-bin/bn_events.py?actualframe=" + escape(actualframe)              + "&totalframes=" + escape(lastframe)              + "&seconds=" + escape(seconds);             //var url = "/cgi-bin/bn_events.py?actualframe=" + escape(actframe);             request.open("get", url, true);             request.onreadystatechange = updatepage;             request.send(null);             actualframe++;             } else {             document.getelementbyid("returnedstatus").value = "done.";          } } 

works better now. independent browser...

thanks help. peter


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -