Click to See Complete Forum and Search --> : why does it not work?


bddosch
05-09-2003, 05:47 AM
why does it not work?

function paperTotal(code) {
var Papertotalamount = 1;
("document.Order." +code+ "Amount.value")=Papertotalamount;
}

<form action="" method="post" name="Order" id="Order">
<input name="FXAmount" type="text" id="FXAmount" value="0">

<input name="FX" type="radio" value="16.64" onclick="paperTotal('FX')" checked>

What I want to acheive is:

document.Order.FXAmount.value = 1;

gil davis
05-09-2003, 05:58 AM
why does it not work?Because you cannot equate a string to a variable. It is not an object. This will work:
document.Order[code + "Amount"].value = Papertotalamount;

SniperX
05-09-2003, 05:58 AM
Why not just use this?

function paperTotal(code) {
document.Order.code.value = 1;
}

and it should work work

bddosch
05-09-2003, 06:06 AM
Thanks gill

document.Order[code + "Amount"].value = Papertotalamount;

it works perfectly..
I knew it was something like that but I was using brackets an other stuff. Why have you left out the "." after Order??

I am new at JS so I want to learn why we do things..

gil davis
05-09-2003, 10:56 AM
In this case, I treated "Order" as an array object, so the "." is not valid.