0
   

Problem with if else

 
 
SusanB
 
Reply Mon 27 Oct, 2014 07:07 pm
I an new to Javascript, I have coded a form to estimate the cost of accommodation. It is doing everything OK but I need to add an if statement. For example: If nights = 4 or < 7 then they get the discount. I have got the discount organised but not sure how or where to add the if statement. If they stay 7 nights then they get a night free (135). Need to add this too. Do I need a new function? Your help would be appreciated. Thanks

Code:<SCRIPT language = JavaScript>

function calculate() {
A = document.frmOne.txtNights.value
B = document.frmOne.txtTwoAdults.value
C = document.frmOne.txtExtraAdults.value
D = document.frmOne.txtChildren.value

A = Number(A)
B = Number(B)
C = Number(C)
D = Number(D)

E = (A * 135)
document.frmOne.txtTot2Ads.value = E
F = (A * C)*35;
document.frmOne.txtXads.value = F
G = (A * D)*15;
document.frmOne.txtkids.value = G
H = (E + F + G)
document.frmOne.txtCost.value = H
I = (H * 10)/100;
document.frmOne.discount.value = I


}
</SCRIPT>

  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 707 • Replies: 0
No top replies

 
 

Related Topics

 
  1. Forums
  2. » Problem with if else
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 04/19/2024 at 04:56:58