82 users online (0 members and 82 guests)  


  Results 1 to 3 of 3

Related

  1. I can't figure this out...    Forum: Website Scripts Forum
    Replies: 5
  2. convert a perl variable to javascript variable    Forum: Javascript Forum
    Replies: 0
  3. Replies: 5
  4. can't reset frame size    Forum: HTML Forum
    Replies: 0
  5. form reset    Forum: HTML Forum
    Replies: 1
  1. #1
    Bad_Oscar's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2005
    Posts
    2

    Question Can't figure out how to reset variable outside function

    I am new to Javascript and am supposed to develop a script that uses HTML FORM to provide input, then use that input(a number) to perform a calculation and return a value. The input is hours parked in a parking garage and the output is the amount owed). I have a script working but does not do one last thing. I have the current customer's total displayed and the running total displayed but I need to be able to store the running total at the end of "day 1" and then reset the customer's total and running total to 0 and run the function over again for "day 2". Here's what I got so far........any help would be greatly appreciated, I'm new at this.

    <script language="javascript">
    <!--Hiding Javascript


    var _total=0;
    function calculateCharges (form){
    var _hours=Math.ceil(form.fhours.value);
    if (_hours >= 0) {
    if (_hours == false) {
    amount_owed.innerText="Try Again.";
    }
    else {
    if (_hours <= 3) {
    price=2.00;
    }
    else if (_hours > 3 && _hours <= 18){
    price=Number(0.5 * (_hours - 3) + 2);
    }
    else {
    price=10.00;
    }
    amount_owed.innerText="Current Customer's Total: $" + price + ".";
    _total=_total + price;
    amount_total.innerText="Running Total: $" + _total;

    }
    }
    else amount_yester.innerText="Yesterday's Total: $" + _total;
    }
    -->
    </script>
    </head>

    <body>

    <form name="myForm">
    <p> </p>
    <p> </p>
    <table border="0" width="100%">
    <tr>
    <td>Enter Number of Hours Parked<br>
    <input type="text" name="fhours" value="Enter Amount of Hours.."><br>
    <input type="button" value="Submit" onClick="calculateCharges(this.form);"><br>
    </td>
    </tr>
    <tr>
    <td height="30" valign="middle" align="center"><div id="amount_owed">Current Customer's Total: $0.00</div>
    </td>
    </tr>
    <tr>
    <td><div id="amount_total">Total receipts: $0.00</div></td>
    </tr>
    <tr>
    <td><div id="amount_yester">Yesterday's Total: $0.00</div></td>
    </tr>
    </table>

    </form>


    Any help would be appreciated!

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Hi, welcome to the forums.

    Just to claify, do you mean it to make a list for each submission? Which grows for each entry you put in?
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    Bad_Oscar's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2005
    Posts
    2

    Smile Ummmmm

    Right now, it will store the calculated value of each entry and continually add it to the total. I want to create an event (button onClick) that will store the total for further processing and then reset the _total so the entire process can be repeated.

    I.E. - When one day ends, the total is recorded and saved. And then the next day starts fresh.

    Does that help? I'm really new at this.

    Thank you very much for your help!



Tags for this Thread