Results 1 to 4 of 4

Thread: including a variable

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Posts
    150

    including a variable

    if i put a line of code like that :

    document.forms[0].nameoftextbox.value

    between the nameoftextbox and value, i want to include a variable in that line so i'll be looping

    that the names nameoftextbox_1

    nameoftextbox_2
    nameoftextbox_3
    nameoftextbox_4
    nameoftextbox_5

    for...x...{

    alert(document.forms[0].nameoftextbox_x.value


    }

    is there a way

  2. #2
    Fanatic Member Blade's Avatar
    Join Date
    Jan 1999
    Location
    Stoke-on-Trent, UK
    Posts
    527
    sure..
    you can use:
    Code:
    var objTextBox;
    
    //loop with x
    
    objTextBox = eval('document.forms[0].nameoftextbox_' + x);
    
    alert(objTextBox.value);
    
    
    //until x=whatever
    Blade

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Posts
    150
    Thank you very much

    EVAL....that was the thing

    you've been a great help

  4. #4
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Okay, I think we should start ignoring cross posters.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width