phpcode wrote:[color=blue]
> I have a javascript function as follows:
>
> function myfunction(formName,formField) {
> parseInt(document.formName.formField.value) +=1;
> }
>
> Then I can call the function when needed like this:
>
> myfunction(users,username);
>
> Here is my problem:
>
> Javascript does not evaluate the arguments passed to the function.
> Instead, it tries to use the arguments literarilly.
>
> So instead of this:
>
> parseInt(document.users.username.value) +=1;
>
> javascript is actually looking for this:
>
> parseInt(document.formName.formField.value) +=1;
>
> I have also tried the following without success:
>
> parseInt(eval(document.formName.formField).value) +=1;
>
> Any suggestions on how to solve this problem?
>[/color]
You start by reading the group FAQ.
function myFunction(users,username){
parseInt(document.forms[users].elements[username].value,10) += 1;
}
Note that I added the radix of 10 to the parseInt call. And whether
parseInt is the best tool for the job depends on what the function is
attempting to do.
--
Randy
comp.lang.javascript FAQ -
http://jibbering.com/faq & newsgroup weekly