This is a discussion on convert a form field value in HH:MM:SS to pure seconds. within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi all... Can anybody tell me about How to convert a form field value in HH:MM:SS to pure ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi all... <SCRIPT LANGUAGE="JavaScript"> function splits(string,text) { // splits string at text var strLength = string.length, txtLength = text.length; if ((strLength == 0) || (txtLength == 0)) return; var i = string.indexOf(text); if ((!i) && (text != string.substring(0,txtLength))) return; if (i == -1) { splitArray[splitIndex++] = string; return; } splitArray[splitIndex++] = string.substring(0,i); if (i+txtLength < strLength) splits(string.substring(i+txtLength,strLength),tex t); return; } function split(string,text) { splitIndex = 0; splits(string,text); } </SCRIPT> <SCRIPT LANGUAGE="JavaScript1.1"> function split(string,text) { splitArray = string.split(text); splitIndex = splitArray.length; } </SCRIPT> <SCRIPT LANGUAGE="JavaScript"> var splitIndex = 0; var splitArray = new Array(); function calculateTime() { splitIndex = 0; split(document.myForm.myTime.value,':'); for (var i=splitIndex-1, j=1, answer=0; i>=0; i=i-1, j=j*60) answer += splitArray[i]*j - 0; document.myForm.mySeconds.value = answer; } </SCRIPT> <FORM NAME="myForm"> <P>HH:MM:SS = <INPUT NAME="myTime" TYPE="TEXT" MAXLENGTH="8" LENGTH="10"> <P>Seconds = <INPUT NAME="mySeconds" TYPE="TEXT"> <P><INPUT TYPE="BUTTON" VALUE="Calculate" onClick="calculateTime()"> </FORM> Thanks... |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Date/time stamp a form field as the form is submitted | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 02-06-2008 09:16 PM |
| Date/Time stamp a form field as the form is submitted | itbarota | HTML, CSS and Javascript Coding Techniques | 2 | 01-17-2008 07:47 PM |
| How can I clear the form field values after the user has submitted the form for clien | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 11-01-2007 10:39 PM |
| How can I set the value of a fileupload form field? | kingmaker | HTML, CSS and Javascript Coding Techniques | 0 | 10-31-2007 02:08 AM |
| How do I set the focus to the first form field? | oxygen | HTML, CSS and Javascript Coding Techniques | 4 | 08-08-2007 02:02 AM |