I have a form field, x_amount, being populated with a static number, based on a selection from a drop down, which for some reason came to me as x_ship_to_address. If 1 or 2 are selected, x_amount is poulated with 25 or 45. If 3 or 4 are selected, the user enters a value into payment_mount and then x_amount becomes payment_amount x 1.03. I want, if a user selects 1 or 2, then both payment_amount and x_amount are populated with 25 or 45. Here is the JS that is working to populate x_amount with a static number:
function SI_money(amount) {
// makes sure that there is a 0 in the ones column when appropriate
// and rounds for to account for poor Netscape behaviors
amount=(Math.round(amount*100))/100;
return (amount==Math.floor(amount))?amount+'.00':((amount*10==Math.floor(amount*10))?amount+'0':amount);
}
function calcTotal(){
var total = document.getElementById('x_amount');
var amount = document.getElementById('payment_amount');
var payment = document.getElementById('x_ship_to_address');
if( payment.selectedIndex == 0)
total.value = 'select Type of Payment from dropdown';
else if( payment.selectedIndex == 3 || payment.selectedIndex == 4 )
total.value = SI_money(parseFloat(amount.value * 1.03));
else if( payment.selectedIndex == 1 )
total.value && amount.value = SI_money(25.00);
else if( payment.selectedIndex == 2 )
total.value = SI_money(45.00);
}
I think I want the last two ifs of calcTotal to be something like:
else if( payment.selectedIndex == 1 )
total.value && amount.value = SI_money(25.00);
else if( payment.selectedIndex == 2 )
total.value && amount.value = SI_money(45.00);
But adding the && throw the errors. I think I'm just missing something about the syntax - how do I say both fields get populated with the correct static number?