Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Newbie needs help!!

  1. #1
    Join Date
    Sep 2006
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Newbie needs help!!

    I am probably taking on more than a beginner should but I’m working on a reservation form that is 2 phases.

    Phase 1 is to calculate reservation details so the guest has a detailed idea of the costs and a total as well as a few other things.

    Phase 2 is to transfer the reservation details from one form to another with different field names so it can then be submitted to a shopping cart for secure information gathering.

    The current test form can be found at: http://www.sunkissvillas.com/test/zp...servation2.htm

    Here is the logic behind the calculation side of the script (center form):

    1. Guest selects arrival and departure date (ideally the script would calculate the difference between arrival and departure dates and insert the number of nights in the “nights” field but that would be a plus for the future).
    2. Guest enters number of nights.
    3. Guest selects season for weekly rate or longer or nightly rate from drop down menu.
    4. Rental cost is automatically calculated by (number of nights * rate selection)
    5. If stay is less than 7 nights a cleaning fee is automatically added.
    6. Guest selects pool heat and pool heat field is automatically calculated (number of nights * 25.00)
    7. Discount is determined (if stay is longer than 13 nights discount is automatically calculated by % of rental cost)(14-20 nights = 10%, 21-27 nights = 15%, 28 or more nights = 20%)
    8. Total is automatically calculated (running total as costs are added.)
    9. Amount due is determine (if arrival date is less than 8 weeks away amount due now = total) (if arrival date is more than 8 weeks away amount due now = (rental cost * .30)(30%)
    10. Balance due date is determine (if arrival date is less than 8 weeks away balance due date = “today”) (if arrival date is more than 8 weeks away due date = arrival date – 8 weeks)

    I have part of the form working properly and calculating but I have run into a problem with the “if/else” portion of the form and running totals.

    I have a script that should work to do the date difference calculations but I haven’t added it in yet.

    I would like to get this thing working properly because it would be a great system but I really want to understand the ins and outs of the script and what it is doing and why it is doing it and also if there is a better way to do it.

    Any and all help would be greatly appreciated.
    Mark

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Doing this in Javascript is not a good idea. Javascript is controlled by the user, and can be bypassed if the user so wishes. You should do this server-side, with a server-side language such as PHP, ASP, Java, or Python.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Sep 2006
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Twey,
    Thanks for the feedback. Ultimately I don't care how it gets scripted, just as long as its maintains functionality and easy of use. I do have one question, I understand about users possibly making changes and then submitting but can't that be avoided for the most part by making fields "read only"?

    I'd be happy to do it in PHP but that will take a little more help. I'm willing! Just show me how to convert the code or give me the equivalents. I still want to understand this regardless of what language it's in. Lead on if you have the time.
    Mark

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I do have one question, I understand about users possibly making changes and then submitting but can't that be avoided for the most part by making fields "read only"?
    No. Don't be fooled by what seems to be possible. The user can submit any data, and make it appear to come from any form control. This includes <select> elements, readonly elements, radio buttons, and all those other things that you thought were safe. Javascript is in the same boat: it's client-side, so the user has total control over it. The user can effectively disable parts of it, modify it while it's running, or just completely ignore it.
    I'd be happy to do it in PHP but that will take a little more help. I'm willing! Just show me how to convert the code or give me the equivalents.
    Do you know PHP, and does your server have it installed and enabled?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Sep 2006
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Twey,
    Thanks for the insite.

    I know some PHP but I'm new to that also. I use a php form handler on my site now and have followed the flow through the code and understand about as much as I do in JS. It works well so yes PHP is installed and enabled on my server.

    It's unfortunate because I just got more of the form working properly. Besides the date calculations the only thing that I haven't been able to get working right is the discount calculation. Works nice otherwise.
    Mark

  6. #6
    Join Date
    Sep 2006
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hey Twey,
    I still want to do this script in PHP but in the mean time can you tell me why the "discount" part of the script isn't working. I'm doing an "onFocus" in the discount field for the discount function. Originally I had the cleaning calculation and discount function together in one script but coulnd't get it to work that way either so I split it into 2 scripts, one for cleaning - which has always worked, and the other for discounts which has never worked. I renamed the discount function and changed the onFocus for that field to match but it still doesn't work. Here is the scripts the way they are now:

    Code:
    <SCRIPT language=JavaScript>
    
    function Calculate()
    {
       // calculate total
       
    	if (charges.duration1.value < 7)
    	charges.cleaning.value = 110.01;
    	
    	else
    	charges.cleaning.value = 0.00;
    				   
       //charges.total.value = parseFloat(charges.rentalcost.value) 
    	//+ parseFloat(charges.pheat.value) + (charges.cleaning.value) + (charges.SecurityDep.value) - (charges.discount.value) + (charges.tax.value);
    	
    }
    </SCRIPT>
    <SCRIPT language=JavaScript>
    function Calc()
    {
       // calculate discount amount
       
    	if (charges.duration1.value > 27)
    	charges.discount.value = charges.rentalcost.value * .2;
    	
    	else if (charges.duration1.value > 20 && < 28)
    	charges.discount.value = charges.rentalcost.value *.15;
    	
    	else if (charges.duration1.value > 13 && < 21)
    	charges.discount.value = charges.rentalcost.value *.10;
    	
    	else (charges.duration1.value > 6 && < 14)
    	charges.discount.value = charges.discount.value + 0.00;
    			   
       //charges.discount.value = parseFloat(charges.discount.value)
    	//+ parseFloat(charges.pheat.value)
    	//+ parseFloat(charges.cleaning.value)
    	//+ parseFloat(charges.SecurityDep.value)
    	//- parseFloat(charges.discount.value)
    	//+ parseFloat(charges.tax.value);
    }
    </SCRIPT>
    Here is the input field code:

    Code:
    <input onFocus=Calculate(); name="cleaning" type="text" class="inputnum" id="cleaning" size="5" maxlength="5" readonly />
    Code:
    <input onFocus="Calc();" name="discount" type="text" class="inputnum" id="discount" size="7" maxlength="7" readonly />
    What part of this don't I understand? The "parseFloat" I commented out because I didn't need it.
    Mark

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The object "charges" is never defined.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Sep 2006
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    OK, but why does the first script (cleaning script) work and the discount part doesn't? I didn't do anything different for the first part over the second (I didn't define it either.) How do I define it?
    Mark

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Instead of "charges.cleaning.value", for example, you probably mean "document.forms['charges'].elements['cleaning'].value", I'd guess.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Sep 2006
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Still doesn't work. I've tried every variation for field definition I can think of. At least 50 configuration, including putting the scripts together, etc. With the following scripts the cleaning fee still works but the discoutn does not.

    Code:
    <SCRIPT language=JavaScript>
    
    function Calculate()
    {form1 = document.forms['charges'].elements['cleaning'].value
       // calculate total
       
    	if (document.forms.charges.duration1.value < 7)
    	document.forms.charges.cleaning.value = 110.01;
    	
    	else
    	document.forms.charges.cleaning.value = 0.00;
    				   
       //charges.total.value = parseFloat(charges.rentalcost.value) 
    	//+ parseFloat(charges.pheat.value) + (charges.cleaning.value) + (charges.SecurityDep.value) - (charges.discount.value) + (charges.tax.value);
    	
    }
    </SCRIPT>
    <SCRIPT language=JavaScript>
    function Calc()
    {form1 = document.forms['charges'].elements['discount'].value
       // calculate discount amount 
       
    	if (document.forms.charges.duration1.value > 27)
    	document.forms.charges.discount.value = document.forms.charges.rentalcost.value * .2;
    	
    	else (document.forms.charges.duration1.value > 20 && < 28)
    	document.forms.charges.discount.value = document.forms.charges.rentalcost.value *.15;
    	
    	else (document.forms.charges.duration1.value > 13 && < 21)
    	document.forms.charges.discount.value = document.forms.charges.rentalcost.value *.10;
    	
    	else (document.forms.charges.duration1.value > 6 && < 14)
    	document.forms.charges.discount.value = document.forms.charges.discount.value + 0.00;
    			   
       //charges.discount.value = parseFloat(charges.discount.value)
    	//+ parseFloat(charges.pheat.value)
    	//+ parseFloat(charges.cleaning.value)
    	//+ parseFloat(charges.SecurityDep.value)
    	//- parseFloat(charges.discount.value)
    	//+ parseFloat(charges.tax.value);
    }
    </SCRIPT>
    Any more thoughts?
    Thanks,
    Mark

Bookmarks

Posting Permissions

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