I have the code below that adds the values of form fields and gives total amount. I got the code online as I am new to Javascript and can’t write it myself yet. It works fine but I now need to add another form field value to the addition calculation. I have searched the internet and tried various methods to solve the problem to no avail. The form field is a text input field called “tip”. I would think it would take a javascript expert about 30 seconds to write the new field into the existing code, thus saving my sanity. Help will be greatly appreciated.
[CODE]
<script type=”text/javascript”>
function Calc(){
var person1 =document.getElementById(‘ead2’).options[document.forms[‘form1’]
.elements[‘ead2’].selectedIndex].getAttribute(‘id’);
var person2 = document.getElementById(‘ess2’).options[document.forms[‘form1’]
.elements[‘ess2’].selectedIndex].getAttribute(‘id’);
var result = (parseInt(person1) + parseInt(person2));
var totalPassenter = result;
var luggage = document.getElementById(‘elg’).value;
var canCarry = totalPassenter * 2;
if(totalPassenter != 0 && luggage > canCarry) {
var extraLuggage = luggage – canCarry;
var extraPay = extraLuggage * 5;
document.getElementById(‘elg2’).value = extraPay;
} else{
document.getElementById(‘elg2’).value = 0;
}
VField1=eval(document.form1.ead2.value)
VField2=eval(document.form1.ess2.value)
VField5=eval(document.form1.ech2.value)
VField7=eval(document.form1.elg2.value)
d=VField1+VField2+VField5+VField7
document.form1.fare.value = d;
}
</script>