×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Help with getting the value from a text field...

Help with getting the value from a text field...

Help with getting the value from a text field...

(OP)
I need help getting the value from a text box when the name of the text box is in a variable.  

So normally, you can simply go:
myval = document.form.textbox.value;

But what I have is:
BoxName = "document.form.textbox.value";  

So how do I get the value from the text box using the name that's stored in the variable 'BoxName'?  

Thanks!  

RE: Help with getting the value from a text field...

this is why you should never use the implied reference.

always do this:

CODE

var BoxName = document.forms['form'].elements['textbox'].value;


 
*cLFlaVA
----------------------------

http://www.coryarthus.com/

RE: Help with getting the value from a text field...

(OP)
Sorry, new to JS, so maybe I misunderstood what you said.  But based on your post, my code looks like this:

BoxName = document.forms['forms2'].elements['textfield1a1'].value;
myvalue = BoxName;

That didn't work.  

RE: Help with getting the value from a text field...

show more of your code.


 
*cLFlaVA
----------------------------

http://www.coryarthus.com/

RE: Help with getting the value from a text field...

(OP)
That's essentially it.  Not much more to it than that.  

The exact code is this:

for (col = 1; col <= 16; col ++)
{
   for (row = 1; row <= cNumRows; row ++)
   {
      szFieldName = "'textfield" + parseInt(row) + "a" + parseInt(col)+ "'";
      BoxName = document.forms['form2'].elements[szFieldName].value;
      rgValues[col] = rgValues[col] + parseInt(BoxName);
   }
}

However, I did write a small piece of test code with everything hard coded and it still didn't work (which is basically the code snippet I already posted):

boxname = document.forms['form2'].elements['textfield1a1'].value;
myval = boxname;

RE: Help with getting the value from a text field...

that can't be the exact code, because you reference a variable (cNumRows) that is never declared.

anyway, try this:

CODE

for (col = 1; col <= 16; col ++) {
   for (row = 1; row <= cNumRows; row ++) {
      szFieldName = "textfield" + row + "a" + col;
      BoxName = document.forms['form2'].elements[szFieldName].value;
      rgValues[col] = rgValues[col] + parseInt(BoxName);
   }
}

and what are you doing with rgValues?


 
*cLFlaVA
----------------------------

http://www.coryarthus.com/

RE: Help with getting the value from a text field...

(OP)
Thanks!  That works!  

BTW, that was just the relevant code section.  cNumRows is declared much earlier.  

Thanks again!  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close