Click to See Complete Forum and Search --> : error: object doesn't support this property or method


megan_t
01-22-2004, 10:27 AM
Hi,

I'm trying to develop somewhat of a dynamic form, and I've run into some trouble. The page uses both radio buttons and check boxes so that the user can choose what he or she wants to purchase, and I'm trying to get the Registration cost (radio button) and total cost (registration + event costs (checkboxes)) to display. The checkboxes seem to work all right, but the browser gives me this error message: "Object doesn't support this property or method" referencing a line of code in function calc() -- RegCost = parseFloat(Reg[i].value);

I don't really know what I'm doing, so any help would be appreciated. Thanks

Sorry so long!



function calc()
{
with (document.myform)
{
Event1Total.value = format(Event1.value * Event1Cost);
Event2Total.value = format(Event2.value * Event2Cost);
Event3Total.value = format(Event3.value * Event3Cost);
Event4Total.value = format(Event4.value * Event4Cost);
Event5Total.value = format(Event5.value * Event5Cost);

for (i=0; i < Reg.length; i++)
if (Reg[i].checked)
RegCost = parseFloat(Reg[i].value);

total.value = format (Regcost + parseFloat Event1Total.value) + parseFloat(Event2Total.value) + parseFloat(Event3.value) + parseFloat(Event4.value)+ parseFloat(Event5.value));
}
}

<SNIP>

<input type="radio" value="250" name="Reg" id="Reg" checked onclick="calc()">
Full &mdash; $250/person <p>
<input type="radio" value="100" name="Reg" id="Reg" onclick="calc()">
Student &mdash; $100/person <br>
</td>
<td> <input type="text" id="RegCost" name="RegCost" size="6" readonly>

Fang
01-22-2004, 11:00 AM
You can have multiple name="Reg", but not with id's.
id's must be unique.

megan_t
01-22-2004, 11:29 AM
Thanks for getting back to me. I've been working off an example from a JavaScript Reference book -- I think it might have been the bible, and I thought they did the same thing:

var shippingCost=0

<snip>

function calc() {

for (i=0; i < shipping.length; i++)
if(shipping[i].checked)
shippingCost = parseFloat(shipping[i].value);

<snip>

<em>shipping</em>
Next day: <input type="radio" value="12" name="shipping" id="shipping" checked onclick="calc()">

2-day: <input type="radio" value="7" name="shipping" id="shipping" checked onclick="calc()">

Standard: <input type="radio" value="3" name="shipping" id="shipping" checked onclick="calc()">

Fang
01-22-2004, 11:36 AM
id's must be unique
Change them first. :)
You may still get an error, but without the full/working script a solution will be difficult.

megan_t
01-22-2004, 11:43 AM
if i change the ids, i'm assuming i need to alter function calc() accordingly. right? how should i do that?

and i'm very happy to share all the code. the faq led me to believe that people wouldn't appreciate that.

thanks so much
:)

Fang
01-22-2004, 01:06 PM
It's your id's that is causing the problem:
1. Have only unique id's
2. Do not have variable names the same as an id.
ie. var RegCost = 0; and <input type="text" id="RegCost" name="RegCost" size="6" readonly>
You are confusing your browser.
Change your id's and variable(s) and it will run correctly

megan_t
01-22-2004, 01:36 PM
Thanks so much!

Fang
01-22-2004, 01:39 PM
Watch your id's :D