0

I am having trouble running this code, any one has idea what could be wrong with it?

please check line # 4

for(i=0; i<document.anyForm.elements.length; i++) {
    element_type = document.anyForm.elements[i].type;
    if(element_type.toUpperCase() == "TEXT" || element_type.toUpperCase() == "TEXTAREA") {
        var parse(document.anyForm.elements[i].name) = document.anyForm.elements[i].value;
    }
}
4
  • 1
    What is the question? Do you get an error? What is the expected result? What is the result you get? Commented Feb 9, 2012 at 19:00
  • For some reason its nor working... do you think if this is correct: var parse(document.anyForm.elements[i].name) = document.anyForm.elements[i].value; Commented Feb 9, 2012 at 19:02
  • 1
    Again: Do you get an error. What is the expected result? What is the result? Doesn't work is really vague. Commented Feb 9, 2012 at 19:03
  • Nah no errors... As you can see I am trying to dynamically define variable names/values that are drived from form elements Commented Feb 9, 2012 at 19:10

1 Answer 1

1
var parse(document.anyForm.elements[i].name)

This is incorrect. you either need to define a variable or invoke a function var before the function invocation is invalid.

EDIT:

you can use an object to store the name:value pairs:

var obj = {}; // before loop

//in loop
obj[document.anyForm.elements[i].name] = document.anyForm.elements[i].value;
Sign up to request clarification or add additional context in comments.

1 Comment

yes I believed the problems lies here, any suggestion? to dynamically define variable names (that are named after form elements)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.