Jump to content

trying to print out a javascript array into csv format, having difficulties


phpfreakjav

Recommended Posts

Problem 1 : is not following my css command CHECK THE displayx function

Problem 2 : is giving me a comma in the last digit.

Thanks for all your help

<html>
<head>
<title>Accuracy Testing System for Parkinson Patients</title>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
<style type="text/css">
.box1{float:left;}
.box2{float:left;}
</style>
</head>

<body onmousemover="follow()">


<!--<body></body>-->


<center><img src="Images/MainHome72b.gif"></center>


<br><script language="JavaScript">
<!--
var mousex=new Array();
var mousey=new Array();
var timecounter=new Array();
var d = new Date();
var getmin=new Array();
var i;
var j=0;
var k;
var recordcount=0;
var repeat;
var repeat2;
var repeat3;
var speed=50;
var timerate=20; //milliseconds
;   //getUTCMilliseconds()

timecounter[0]=0;



function startthis() {
  recordcount=1;
  i=0;
  mousex=new Array();
  mousey=new Array();
  recordthis();
  }
function recordthis() {
getmin[0]=d.getUTCSeconds()+d.getUTCMilliseconds()/1000;


  if (maxnum.value=='' || isNaN(maxnum.value) == true || maxnum.value<0) {
  if (recordcount==1) {
  mousex[i]=mousefollow.offsetLeft;
  mousey[i]=mousefollow.offsetTop;


i++;
timecounter[i]=timecounter[i-1]+timerate;
getmin[i]=getmin[i-1]+timerate/1000;

  k=i;
  textfield.value='No Time Limit';
  }
  }
  else {
  if (recordcount==1) {
  if (i<maxnum.value) {
  mousex[i]=mousefollow.offsetLeft;
  mousey[i]=mousefollow.offsetTop;
  i++;
    timecounter[i]=timecounter[i-1]+timerate;
   getmin[i]=getmin[i-1]+timerate/1000;



  k=i;
  textfield.value='Time Left'+(maxnum.value-i)+'/50seconds';
  }
  else {
  recordcount=0;
  textfield.value='Time is Over';}
  }
  }
  repeat=setTimeout("recordthis()",timerate);
  }
function stopthis() {
  clearTimeout("repeat");
  recordcount=0;
  }
function playthis() {
  clearTimeout("repeat");
  clearTimeout("repeat3");
  recordcount=0;
  if (j<i-1) {
  arrow.style.pixelLeft=mousex[j];
  arrow.style.pixelTop=mousey[j];
  arrow.style.visibility='visible';
  j++;
  repeat2=setTimeout("playthis()",speed);
  }
  else {clearTimeout("repeat2");
  arrow.style.visibility='hidden';
  j=0;
  }
}

function displayx(x)
{
document.write(' <div class="box1"> ');



for(var i =0; i<mousex.length; i++)
{
if(i==0)
	{
	document.write(mousex[i]) ;
	document.write("<br/>") ;
	}
if(i==mousex.length)
	{
	document.write(mousex[i]) ;
	document.write("<br/>") ;
	}
	else 
	{
	document.write(mousex[i]) ;
	document.write(",");//a comma
	document.write("<br/>") ;
	}
}//end for


document.write("</div>");

}//end function

function showthis(){

displayx(mousex);
  //	document.write("x: " + mousex + "<br>y: " + mousey +"<br><br><br>The time interval (record the mouse position vector) is every"+ timerate + " milliseconds" + "<br>recorded time (millisec): " + //timecounter+"<br>real time: " +getmin);
//	document.write("\n sss " ;

}


function rewindthis() {
  clearTimeout("repeat");
  clearTimeout("repeat2");
  recordcount=0;
  if (k>0) {
  arrow.style.pixelLeft=mousex[k-1];
  arrow.style.pixelTop=mousey[k-1];
  arrow.style.visibility='visible';
  k--;
  repeat3=setTimeout("rewindthis()",speed);
  }
  else {clearTimeout("repeat3");
  arrow.style.visibility='hidden';
  k=i;
  }
  }
function follow() {
  mousefollow.style.pixelLeft=document.body.scrollLeft+event.clientX;
  mousefollow.style.pixelTop=document.body.scrollTop+event.clientY;



/*mousefollow.style.pixelLeft=document.getElementById('scrollLeft')+event.clientX;
mousefollow.style.pixelTop=document.getElementById('scrollTop')+event.clientY;*/
  }




  // -->
</script>
<div id="arrow" style="position:absolute; width:12px; height:21px; z-index:1;visibility:hidden"><img src="Images/Cursor.gif"></div>
<div id="mousefollow" style="position:absolute; width:12px; height:21px; z-index:1;visibility:hidden">.</div>
<input type="text" name="maxnum" size="4" maxlength="4">
<input type="button" onClick="startthis()" value="Record">
<input type="button" onClick="stopthis()" value="Stop">
<input type="button" onClick="speed=50;playthis()" value="Play"><input type="button" onClick="speed=2;playthis()" value="Fast Play">
<input type="button" onClick="speed=150;playthis()" value="Slow Play">
<input type="button" onClick="speed=50;rewindthis()" value="Reverse Play">
<input type="button" name="textfield" style="width:100px" value="No Time Limit">
<input type="button" onClick="speed=50;showthis()" value="Show Mouse values">



<br><br><br>
<center><img src="Images/bg.png"></center>





</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.