...

View Full Version : function help



esthera
09-03-2006, 10:11 AM
can someone help me with teh following function I am trying to write.

my code:

function PaymentsDelete(i){
if(document.payments.deleteme.checked){
alert('delete');
myfield=amount+i;
documents.payments.myfield.value=0;
}
}

What I want this to do is to take the i passed in and set the field in the payments form name amount and i to 0.
In other words if i is 1 then the script should set payments.amount1=0.

can someone help me get this working. Now it seems to be ignoring the statement.

Mr J
09-03-2006, 10:39 AM
You may just have missed a typo in this line

documents.payments.myfield.value=0;

remove the s from documents to give you

document.payments.myfield.value=0;

esthera
09-03-2006, 10:43 AM
thanks - but it's still not working.
is that the right way to access it setting myfield to the field name and doing document.payments.myfield??

Mr J
09-03-2006, 10:47 AM
Try it this way


function PaymentsDelete(i){
if(document.payments.deleteme.checked){
alert('delete');
myfield="amount"+i;
document.payments[myfield].value=0;
}
}

or this way depending on your preference




function PaymentsDelete(i){

myForm=document.forms["payments"]

if(myForm["deleteme"].checked){
myForm["amount"+i].value=0;
}

}

Kor
09-03-2006, 12:14 PM
err what type hase the control "deleteme". A checkbox? If so, I guess that you have a collection of checkboxes with the same name. In this case you should circle through the collection or use the index. Can we see your HTML code?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum