/    Sign up×
Community /Pin to ProfileBookmark

Need calculation code for this form

Hi,
how can this calculation be made possible. Is JS the right code for it too?
On this form:
[URL=http://www.e-travelbg.com/HotelFormTest1.htm]http://www.e-travelbg.com/HotelFormTest1.htm[/URL]
I have option for [B]Number of Adults[/B] 0 to 5 and [B]Number of Children [/B] 0 to 5.

How can I make, let’s say:
[B]1.[/B] The value for:
adult to be $50.00 and for
a child to be $25.00.
[B]2.[/B] On click of CALCULATE button, if I had selected 2 adults and 2 children, the calculation would show $150.00.
[B]3.[/B] If that’s not already complicated, how can the CALCULATE take into account if the reservation (Check in / Check out calendar) was for two or more days; so the CALCULATION button has to read the calendar!
[B]4.[/B] And if that’s not complicated enough, let’s say there are 2 seasons:
Season 1 — from Jan 1 till June 30
Season 2 — from July 1 till Dec 30
In season 1, adult is $60
In season 2, adult is $50
In season 1, child is $30
In season 2, child is $25

The values, seasons, number of people and the way the form is set up will not exactly be the same, but I just want to get a clue of the set up, so I can modify it in the future.

For now, CHECK AVAILABILITY will be only a PHP e-mail submission form. It’s not functional right now, and I would worry about it after the calculation is functional, not right now.

Please go slow with explanations, since I am not too keen with coding.

Thanks.

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYDec 08.2005 — I don't know javascript but if you press the calculate button that would be easy to do with PHP (even the thing with the season)

Do you have PHP on your server?
Copy linkTweet thisAlerts:
@jamesx521authorDec 08.2005 — Thanks.

I haven't set the PHP form for submission yet. Yes, I can use PHP on the web host provider.
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYDec 08.2005 — ok, so first put form tags around it( and set action to the page itself) change your calculate button to:
<i>
</i>&lt;input type="image" title="Calculate" src="images/Calculate_Button.gif" onmouseover="this.src='images/Calculate_ButtonR.gif'" onmouseout="this.src='images/Calculate_Button.gif'"/&gt;


What we could do after these change is when the user clicks on "Calculate" the calculationis done and the form is changed:
[list]
  • [*]the values appear as hidden fields

  • [*]the action attribute is changed to the PHP script that will send the e-mail

  • [*]and the value can be displayed if you want

  • [/list]
    Copy linkTweet thisAlerts:
    @FromU2MEDec 08.2005 — Have you checked with any of the javascripts on javascript.internet.com? They might not be customized, but they just might give you the push in the right direction!

    Though, if you're not keen in scripting that's something else ?
    Copy linkTweet thisAlerts:
    @LiLcRaZyFuZzYDec 08.2005 — --edit
    Copy linkTweet thisAlerts:
    @FromU2MEDec 08.2005 — I'll get back to you with a script later.

    [B]UPDATE:[/B] I've finished the script now! I'll send the complete script to your private inbox tomorrow! It's a bit vast and complex, but I hope it'll do some use! ?
    Copy linkTweet thisAlerts:
    @jamesx521authorDec 09.2005 — LiLcRaZyFuZzY, you are suggesting PHP?

    while

    FromU2ME, you are suggesting JS? ...And you have the code done for me already: Wow, thanks. I'll check it tomorrow.
    Copy linkTweet thisAlerts:
    @LiLcRaZyFuZzYDec 09.2005 — LiLcRaZyFuZzY, you are suggesting PHP?
    [/QUOTE]

    yes i was
    Copy linkTweet thisAlerts:
    @jamesx521authorDec 09.2005 — What is the benefit of PHP over JS? Or, maybe I should go ask you that in the PHP forum instead.
    Copy linkTweet thisAlerts:
    @FromU2MEDec 09.2005 — I strongly believe that the task here should be done i JS - since you shouldn't put so much weight on the server script (PHP in your case) every time someone wants to calculate their trip! Besides, it will go a lot faster doing it with JS since it doesn't have to reload a new page when you calculate and you get the result directly!

    Well, I guess you shouldn't expect anything else said since you're on the JavaScript Forum ?

    I've sent the script to your pm, hope you'll find use for it! Enjoy ?
    Copy linkTweet thisAlerts:
    @LiLcRaZyFuZzYDec 09.2005 — 

    the benefit is that javascript might be turned off, in which case your code won't work, php will always work as it is exectued on the server-side, not client-side
    --


    [B]edit:[/B] this calculation won't take any noticeable time in php
    Copy linkTweet thisAlerts:
    @jamesx521authorDec 09.2005 — This is the JS version:

    Form:

    [URL=http://www.e-travelbg.com/HotelFormTest1JS.htm]http://www.e-travelbg.com/HotelFormTest1JS.htm[/URL]

    (Don't use the .htm in my first posting: This .htm here, in this post, is the updated one!)

    Calendar:

    http://www.e-travelbg.com/js/datetimepicker.js

    Right now, the CALCULATION doesn't take into account the calendar, the seasons as well, and the calendars' pop-up windows don't work on Mozilla.

    Thanks.

    -jms
    ×

    Success!

    Help @jamesx521 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.3,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...