Visit The New, Modern Unix Linux Community


Javascript: Edit a script ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Javascript: Edit a script ?
# 1  
Javascript: Edit a script ?

Hi, i got this script but when i hit reset i loose the times in the form box. Can someone please edit this script so when i hit reset i dont loose the times in the form box's and also have a button to reset everything, including the form boxs



<script language="javascript">
// stopwatch script by Brothercake - http://www.brothercake.com/

var base = 60;

var clocktimer,dateObj,dh,dm,ds,ms;
var readout='';
var h=1;
var m=1;
var tm=1;
var s=0;
var ts=0;
var ms=0;
var show=true;
var init=0;
var mPLUS=new Array(
'm0',
'm1',
'm2',
'm3',
'm4',
'm5',
'm6',
'm7',
'm8',
'm9'
);
var ii=0;

function clearALL() {
clearTimeout(clocktimer);
h=1;m=1;tm=1;s=0;ts=0;ms=0;
init=0;show=true;
readout='00:00:00.00';
document.clockform.clock.value=readout;
var CF = document.clockform;
for (ij=0;ij<=9;ij++) { CF[mPLUS[ij]].value = ''; }
ii = 0;
}

function addMEM() {
if (init>0) {
var CF = document.clockform;
CF[mPLUS[ii]].value = readout;
if (ii==9) { ii = 0; } else { ii++; }
}
}


function startTIME() {

var cdateObj = new Date();
var t = (cdateObj.getTime() - dateObj.getTime())-(s*1000);

if (t>999) { s++; }

if (s>=(m*base)) {
ts=0;
m++;
} else {
ts=parseInt((ms/100)+s);
if(ts>=base) { ts=ts-((m-1)*base); }
}

if (m>(h*base)) {
tm=1;
h++;
} else {
tm=parseInt((ms/100)+m);
if(tm>=base) { tm=tm-((h-1)*base); }
}

ms = Math.round(t/10);
if (ms>99) {ms=0;}
if (ms==0) {ms='00';}
if (ms>0&&ms<=9) { ms = '0'+ms; }

if (ts>0) { ds = ts; if (ts<10) { ds = '0'+ts; }} else { ds = '00'; }
dm=tm-1;
if (dm>0) { if (dm<10) { dm = '0'+dm; }} else { dm = '00'; }
dh=h-1;
if (dh>0) { if (dh<10) { dh = '0'+dh; }} else { dh = '00'; }

readout = dh + ':' + dm + ':' + ds + '.' + ms;
if (show==true) { document.clockform.clock.value = readout; }

clocktimer = setTimeout("startTIME()",1);

}


function findTIME() {
if (init==0) {
dateObj = new Date();
startTIME();
init=1;
} else {
if(show==true) {
show=false;
} else {
show=true;
}
}
}




</script>





<form name=clockform>
<table cellpadding=2 cellspacing=0 border=0>
<tr>
<td><input name=clearer type=button value=" reset " onclick="clearALL()"></td>
<td><input name=clock size=12 value="00:00:00.00"></td>
</tr>
<tr>
<td><input name=marker type=button value=" m + " onclick="addMEM()"></td>
<td><input name=starter type=button value="start / pause" onclick="findTIME()"></td>
</tr>
<tr><td colspan=2><b>m 0</b> <input name=m0 size=12></td></tr>
<tr><td colspan=2><b>m 1</b> <input name=m1 size=12></td></tr>
<tr><td colspan=2><b>m 2</b> <input name=m2 size=12></td></tr>
<tr><td colspan=2><b>m 3</b> <input name=m3 size=12></td></tr>
<tr><td colspan=2><b>m 4</b> <input name=m4 size=12></td></tr>
<tr><td colspan=2><b>m 5</b> <input name=m5 size=12></td></tr>
<tr><td colspan=2><b>m 6</b> <input name=m6 size=12></td></tr>
<tr><td colspan=2><b>m 7</b> <input name=m7 size=12></td></tr>
<tr><td colspan=2><b>m 8</b> <input name=m8 size=12></td></tr>
<tr><td colspan=2><b>m 9</b> <input name=m9 size=12></td></tr>
</form>
</table>


Last edited by perleo; 05-23-2003 at 07:01 PM..
# 2  
Replace
Code:
function clearALL() {
clearTimeout(clocktimer);
h=1;m=1;tm=1;s=0;ts=0;ms=0;
init=0;show=true;
readout='00:00:00.00';
document.clockform.clock.value=readout;
var CF = document.clockform;
for (ij=0;ij<=9;ij++) { CF[mPLUS[ij]].value = ''; }
ii = 0;
}

with
Code:
function clearSOME() {
clearTimeout(clocktimer);
h=1;m=1;tm=1;s=0;ts=0;ms=0;
init=0;show=true;
readout='00:00:00.00';
document.clockform.clock.value=readout;
ii = 0;
}

function clearALL() {
var CF = document.clockform;
for (ij=0;ij<=9;ij++) { CF[mPLUS[ij]].value = ''; }
clearSOME()
}

Then replace
Code:
<td><input name=clearer type=button value=" reset " onclick="clearALL()"></td>

with
Code:
<td><input name=clearer type=button value=" reset everything " onclick="clearALL()"></td>
<td><input name=clearer2 type=button value=" reset some things" onclick="clearSOME()"></td>


Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #361
Difficulty: Medium
The rmdir command remove directories, even if they are not empty.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

File edit script exceptions how to pass to script

i wrote script for if file exists script do file edit problem with the script get stuck not existing as for exit i mentioned exit 0 , and how to give the exception for script it should add ./script -- add hi ./script --add "hi how are you" now below script with case it is working for... (0 Replies)
Discussion started by: markjohn1
0 Replies

2. Web Development

Javascript to check field is empty then execute rest of script

I have found this bit of code that nearly does what I want. Basically 3 input fields, I want to copy t2 to t3 as it's typed but only if t1 contains data AND t3 is empty: <input type="text" id="t1" /> <input type="text" id="t2" /> <input type="text" id="t3" /> <script> var t2 =... (4 Replies)
Discussion started by: barrydocks
4 Replies

3. Shell Programming and Scripting

want to use javascript as shell script

<html> <head> <title>Weather & Aviation Page - METAR decoder</title> <meta name="Title" content="Weather & Aviation Page - METAR decoder"> <meta name="Keywords" content="METAR decoder"> <meta name="Publisher" content="SkyStef"> <meta name="Description" content="SkyStefs weather and aviation... (4 Replies)
Discussion started by: anuajay1988
4 Replies

4. Shell Programming and Scripting

Can we edit crontab using a shell script

Hi, Can some one tell me if we can configure the jobs in crontab using a shell script. I know it can be done easily by using "crontab -e", but i just want to know whether we can add a job into the crontab using a shell script. If it can be done, plz suggest the procedure to do it. If it... (6 Replies)
Discussion started by: rudrarajumk
6 Replies

5. Shell Programming and Scripting

Need help in a shell script to edit a tablespace creation script.

Hi, CREATE TABLESPACE aps_blob_large01 DATAFILE '/c2r6u13/u03/oradata/qnoldv01/aps_blob_large0101.dbf' SIZE X 270532608 REUSE DEFAULT STORAGE (INITIAL 134217728 NEXT... (2 Replies)
Discussion started by: rparavastu
2 Replies

6. Web Development

Javascript -> Shell Script

Hi all, I am trying to call a shell script from a javascript function. This works fine and the shell script returns everything I expected BUT I cannot figure out how to pass command line arguments to this shell script. Using GET, I assume the url being called needs to be one string with no... (7 Replies)
Discussion started by: mark007
7 Replies

7. Shell Programming and Scripting

HP-ux: Script edit

Hallo Friends, I have written a script which goes through different directories deleting files but I think there is a shorter way I can do this please help. #!/bin/ksh #set -x cd /minotaur/Data/CFD_Input/E_CIF cd 051 for files in 2008* do rm -rf $file done # cd ../052 for... (3 Replies)
Discussion started by: kekanap
3 Replies

8. Shell Programming and Scripting

script to search and edit scripts

Hi all, can you please help me in this one.. i have a many scripts in a directory & i get many requests to change the code of a particular script. for example file abc.txt contains #!/bin/bash mumbai 102403445 chennai 123980123 delhi 3456268468 kolkata 465376832 #kolkat 462945959 ... (3 Replies)
Discussion started by: geeko
3 Replies

9. Shell Programming and Scripting

How to EDIT file using VI in a script

Hello, How would i go about editing a file using VI within a shell script please? Basically, i want to open a file, clear it's contents and save the file. I found this on the web using "ex" but can't seem to get it to work: ex /home/oconnor/TOOLS/UNIXCMDS/test_ex <<eof_ex dd /*i put... (2 Replies)
Discussion started by: bobk544
2 Replies

10. Shell Programming and Scripting

Calling Shell script in javascript

All I want to call a KORN shell script inside a javascript. Is it possible ? Please help me to do this. I want to return or read from shell script in javascript. Thanx in advance Regards Deepak Xavier (1 Reply)
Discussion started by: DeepakXavier
1 Replies

Featured Tech Videos