That's one way to do it, give each radio a unique ID and then check each one after the other. If you are using a huge form with many radios though, you would be better off using a different technique such as looping through them to find which is checked.
Also, if you are going to do a lot of form stuff with JavaScript I'd recommend looking into using a JavaScript library (I use jQuery, but there are many others such as Dojo, scriptalicious) as they will save you a lot of time.
1) Standards say you can't have multiple elements with the same ID. And ID is supposed to be unique throughout the entire document.
2) Make sure you do server-side verification of this. It wouldn't be too hard at all for me to submit a form that says I have a 4-issue full page advertisement for $0.00
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
//Returns value of the input which is selected, if none is selected returns 0
function getSelectedValue(inp_list) {
for(var i=0,j=inp_list.length; i<j; i++) {
if (inp_list[i].checked) {
return inp_list[i].value;
}
}
return 0;
}
function price_form() {
var grandtotal = 0;
//PROBLEM WAS HERE, document.adform.advertise is returning list of items, not selected item
var advertiseInputs = document.adform.advertise;
var numberofissuesInputs = document.adform.numberofissues;
//Get selected value for both radio button lists
var advertise = getSelectedValue(advertiseInputs);
var numberofissues = getSelectedValue(numberofissuesInputs);
//Rest of the code is untouched
if(numberofissues > 0){
grandtotal = numberofissues * advertise
grandtotal = formatCurrency(grandtotal);
document.adform.grandtotal.value = grandtotal;
}else{
document.adform.grandtotal.value = 0;
}
cctotal = grandtotal * 1.03; // add 3 % to all orders
cctotal = formatCurrency(cctotal);
document.adform.cctotal.value = cctotal;
grandtotal = formatCurrency(grandtotal);
document.adform.grandtotal.value = grandtotal;
}
In IE onChange is fired only when input looses focus, not when value changes. Quick fix would be to add also onClick="price_form()" for each radio input.
Remove ids from the inputs, there is no need for them.