YogeshPancholi
Programmer
Hi folks. I need your JavaScript skills assistance in helping me solve my problem.
In my HTML form I have several <DIVS> where each DIV contains multiple text input box elements. The DIVs are named idDiv_1, idDiv_2... idDiv_n, while within each DIV the input boxes are named From_1, To_1, SomeText_1, From_2, To_2, SomeText_2,... From_n, To_n, SomeText_n (see below).
<FORM>
<DIV NAME="idDiv_1>
<INPUT TYPE="text" NAME="From_1" onChange="doFunc(1);">
<INPUT TYPE="text" NAME="To_1">
<INPUT TYPE="text" NAME="SomeText_1">
... some more <INPUT>
</DIV>
<DIV NAME="idDiv_2>
<INPUT TYPE="text" NAME="From_2" onChange="doFunc(2);">
<INPUT TYPE="text" NAME="To_2">
<INPUT TYPE="text" NAME="SomeText_2">
... some more <INPUT>
</DIV>
...
...
<DIV NAME="idDiv_n>
<INPUT TYPE="text" NAME="From_n" onChange="doFunc
;">
<INPUT TYPE="text" NAME="To_n">
<INPUT TYPE="text" NAME="SomeText_n">
... some more <INPUT>
</DIV>
</FORM>
Now here's my problem:
The parameter in doFunc() identifies the DIV number. Now in doFunc(), I concatenate strings that hold the first part of the INPUT box name(ie. "From_", "To_", and "SomeText_"
with the function parameter and construct valid element names. I want to extract values from some INPUT boxes, do some data manipulation, then replace the resultant values into other INPUT boxes (are you with me so far...???).
This is where I need your expertise. How can I concatenate the strings, extract values from some form elements, and replace values in others??? My javascript doesn't like code as follows:
doFunc(myParm) {
var myVal
var myResult
var myFrom = "From_"
var myTo = "To_"
var myForm = document.forms[0];
var myStr = "myResult = myForm." + myFrom + myParm + ".value"
myVal = eval(myStr)
alert(myVal)
}
What am I doing wrong?? Is it possible to construct element names from several component strings, then use the derived names to manipulate elements??
Any assistance will be greatly appreciated.
Many Thanx...
Yogesh Pancholi
"If a pig loses its voice, is it disgruntled?"
In my HTML form I have several <DIVS> where each DIV contains multiple text input box elements. The DIVs are named idDiv_1, idDiv_2... idDiv_n, while within each DIV the input boxes are named From_1, To_1, SomeText_1, From_2, To_2, SomeText_2,... From_n, To_n, SomeText_n (see below).
<FORM>
<DIV NAME="idDiv_1>
<INPUT TYPE="text" NAME="From_1" onChange="doFunc(1);">
<INPUT TYPE="text" NAME="To_1">
<INPUT TYPE="text" NAME="SomeText_1">
... some more <INPUT>
</DIV>
<DIV NAME="idDiv_2>
<INPUT TYPE="text" NAME="From_2" onChange="doFunc(2);">
<INPUT TYPE="text" NAME="To_2">
<INPUT TYPE="text" NAME="SomeText_2">
... some more <INPUT>
</DIV>
...
...
<DIV NAME="idDiv_n>
<INPUT TYPE="text" NAME="From_n" onChange="doFunc
<INPUT TYPE="text" NAME="To_n">
<INPUT TYPE="text" NAME="SomeText_n">
... some more <INPUT>
</DIV>
</FORM>
Now here's my problem:
The parameter in doFunc() identifies the DIV number. Now in doFunc(), I concatenate strings that hold the first part of the INPUT box name(ie. "From_", "To_", and "SomeText_"
This is where I need your expertise. How can I concatenate the strings, extract values from some form elements, and replace values in others??? My javascript doesn't like code as follows:
doFunc(myParm) {
var myVal
var myResult
var myFrom = "From_"
var myTo = "To_"
var myForm = document.forms[0];
var myStr = "myResult = myForm." + myFrom + myParm + ".value"
myVal = eval(myStr)
alert(myVal)
}
What am I doing wrong?? Is it possible to construct element names from several component strings, then use the derived names to manipulate elements??
Any assistance will be greatly appreciated.
Many Thanx...
Yogesh Pancholi
"If a pig loses its voice, is it disgruntled?"