javascript - Not work with getElementById -


not work getelementbyid ("val5" + i). , input3 not running

i hope code enough info provide

the error somewhere in line

/* digitalinput */

index = input2_offs for(i=0;i<4;i++) getelementbyid("val5"+i).src = valuearray[input2_offs[i]] == "0" ? 'gif/dot_red.gif' : 'gif/dot_gr.gif'

where problem


enter code here  <!--  var req = null; req = ajaxinit(); var postbuffer = new array;  var trace;  /* number of channels per sensor input type */ var inputchannels = 4;  /* max 4 digital inputs          */  var names = new array(); var units = new array(); var offs = new array(); var gain = new array(); var value = new array();  var input2_offs = 25; var input3_offs = 26;  /*     function called on body load , later every 5s     request new set of data controller */ function update() {     var x = math.random()*1000;  /* add random number url avoid caching content in browser */     x=x.tofixed(3);     ajaxgetrequest("/getstate.csv"+"?a="+x,updatetracebuffers);     return false; }  /*     call routine when controller has send data     function separates items in separate arrays :     names, units, offsets , gains  , raw values */ function updatetracebuffers() {      trace = req.responsetext.split('\n');     names = trace[tracenameoffs].split(',');     units = trace[traceunitoffs].split(',');     offs = trace[traceoffs].split(',');     gain = trace[tracegain].split(',');     value = trace[tracedataoffs].split(',');     updatewebsite();                         /* user routine , update items */     if(timerhandle == 0)     {         timerhandle = window.setinterval("update()", 5000);     } }  /* digitalinput */      index = input2_offs;             for(i=0;i<4;i++)     getelementbyid("val5"+i).src = valuearray[input2_offs[i]] == "0" ? 'gif/dot_red.gif' : 'gif/dot_gr.gif';      index = input3_offs;     v = (parsefloat(offs[index]) + parsefloat(gain[index])* parsefloat(value[index])).tofixed(0);             getelementbyid("sens_val6").innerhtml = v;  //-->   <td class="mytd"><div align="center"><img src="gif/dot_red.gif"  width="24" height="24" id="val5"></div></td>   <td id="sens_val6" class="mytd" align="right">&nbsp;</td> 

document.getelementbyid("val5"+i);  

or use:

document.queryselector("val5"+i)

works in modern browsers (ie8+). https://developer.mozilla.org/en-us/docs/web/api/document.queryselector

actually use {} in loops , if statements , forth, it's recommended practice in js.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -