ERROR Object expected

Hi, I am not very fluent n JavaScript, so I apologize upfront if this appears silly.

I took over the design/development of a website and it had a page created using asp, which I had to convert to php. But now the JavaScript doesn’t seem to work.

The error I keep getting in IE is:

Message: Object expected
Line: 96
Char: 1
Code: 0

The html code that calls the functon is as follows:


<input type="radio" name="donationAmount" id="donationAmount" value="10.00">
<input type="radio" name="donationAmount" id="donationAmount" value="20.00">
<input type="radio" name="donationAmount" id="donationAmount" value="30.00">
<input type="radio" name="donationAmount" id="donationAmount" value="40.00">
<input type="submit" value="Paypal" onclick="submitform('paypal');">
<input type="submit" value="Paygate" onclick="submitform('paygate');">

And the javascript function is like this:


<script>

function submitform(whichform)
{

document.forms['paypalform'].amount.value = getRadioValue();
document.forms['paygateform'].AMOUNT.value = parseFloat(getRadioValue().replace('.','')* 7.4); 

if (whichform == 'paypal')
	{
		
		document.forms['paypalform'].submit();
	}
else {

	
	document.forms['paygateform'].submit();
	}

}


function getRadioValue() {
			for (index=0; index < document.amounts.donationAmount.length; i++) {
				if (document.amounts.donationAmount[i].checked) {
					var radioValue = document.amounts.donationAmount[i].value;
					break;
				}
			}
		
		return radioValue;

	}


</script>

If anyone can help me or point me in the right direction, I would be so grateful. Thank you very much!

Object expected is IE’s way of saying “something is missing or misreferenced” (or, something went wrong and I can’t be bothered to tell you what). The line number can’t be trusted either.

It’s probably because your reference to “amounts” or “AMOUNT” is wrong. You’d be better off using proper DOM methods, like getElementsByTagName or getElementsByName and friends. Also, all those radio buttons have the same ID, which is very wrong.

Try this:

<input type="radio" name="donationAmount" value="10.00">
<input type="radio" name="donationAmount" value="20.00">
<input type="radio" name="donationAmount" value="30.00">
<input type="radio" name="donationAmount" value="40.00">
<input type="submit" value="Paypal" onclick="submitform('paypal');">
<input type="submit" value="Paygate" onclick="submitform('paygate');">
function submitform(whichform) {
  var radios = document.getElementsByName('donationAmount'), radioval;
  for (var i = 0; i < 4; i++ {
    if (radios[i].checked) {
      radioval = radios[i].value;
      break;
    }
  }
  if (whichform === paypal) {
    document.getElementById('paypalamount').value = radioval;
  }
  else {
    document.getElementById('paygateamount').value = parseFloat(radioval.replace('.','') * 7.4);
  }
  document.getElementById(whichform+'form').submit();
}

I think you should be able to work out what IDs to give each element.

Just out of curiosity, why does paygate require multiplying by 7.4?

Thank you very much!! It works now. I really appreciate it! :smiley: :smiley: