Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript date in form programing help

    I’ve started a script that I can’t seem to finish on my own so maybe somebody out there can help me or recommend an alternative

    I have a form that when the user enters a serial number the form will display
    The year manufactured
    The city and state where manufactured
    And the the month and day

    Example:
    Serial number: 70108276
    The 7 and 8 represent the year “78”
    010 represent the julian date which would be “January 10”
    276 represent the manufactures code

    I was able to extract the 7 and 8 and concatenate the year 78
    And also 276 to produce the manufacturer.
    How can I convert 010 to display as January 10 or concatenate with the 7 and 8 to produce January 10, 1978
    Below is an example of what I have thus far


    <script language="javascript">
    function findChar()
    {
    var serialOne = document.form1.textbox2.value.charAt(0);
    var serialTwo = document.form1.textbox2.value.charAt(4);
    var dddNum = document.form1.textbox2.value.substring(1,4);
    var pppNum = document.form1.textbox2.value.substring(5,8);
    document.form1.result.value=(serialOne + serialTwo)
    document.form1.result1.value=(dddNum)

    //Manuafactured by
    if ((pppNum >= 1) && (pppNum <= 499)){ pppNum = "Kalamazoo, Michigan";}
    else if ((pppNum >= 500) && (pppNum <= 999)){ pppNum = "Nashville, Tennessee";}

    document.form1.result2.value=(pppNum)

    }

    </script>

    </head>
    <body>

    <Table border="1" width="600"><tr><td colspan="3">
    <form name="form1">
    Enter the serial number&nbsp;<input type="text" name="textbox2" size="10" value="">
    <input type="button" value=" Lookup " onclick="findChar()">&nbsp;<INPUT TYPE="reset" VALUE="Reset">

    </td></tr>
    <tr>
    <td align="center">Production Year</td><td align="center">Production Date</td><td align="center">Manufactured at</td></tr>
    <tr>
    <td align="center"><input type="text" value="" name="result" size="15"></td>
    <td align="center"><input type="text" value="" name="result1" size="15"></td>
    <td align="center"><input type="text" value="" name="result2" size="40"></td>
    </form>
    </tr>
    </table>



    Thanks in advance!

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    620
    Thanks
    1
    Thanked 20 Times in 20 Posts
    Take a look at the following snippit and see if it helps:

    Code:
    var dddNum = prompt('J Date',0);
    MonthDays=new Array(0,31,59,90,120,151,181,212,243,273,304,334);
    MonthNames=new Array('January','February','March',
     'April','May','June','July','August','September',
     'October','November','December');
    MonthNum=0;
    dddWork=dddNum*1;
    dddWork2=dddWork;
    for (i=0; i<=11; i++) {
     if (dddWork > MonthDays[i]) {
      MonthNum=i;
      dddWork2=dddWork-MonthDays[i];
     }
    }
    alert(MonthNames[MonthNum]+' '+dddWork2);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •