Results 1 to 11 of 11

Thread: URGENT JavaScript problem...

  1. #1

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Exclamation URGENT JavaScript problem...

    Hey all.

    I have an .asp page in which a form is created by Server-Side VBScript.

    In the form I have a set of checkboxes named:

    checkbox0
    checkbox1
    .
    .
    .
    checkboxN

    (N can range from about 4 to 10 depending on the creation script)


    I need to use JavaScript to verify the form input.

    How do I refer to these checkboxes in a for loop?

    Is that possible?

    eg:

    for (i = 0; i < N; i++) {
    window.alert(document.form.<B>(checkbox + i)</B>.value)
    }


    This is a big problem for me right now...


    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    try this:
    Code:
    for (i = 0; i < N; i++) { 
    eval("window.alert(document.form.checkbox" + i + ".value) ;");
    }
    not completely sure, but I think it will work.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Thumbs up

    Excellent!

    Cheers dude, you saved me!

    I just couldn't figure the syntax. I never would've got it I don't think. I've been fiddling for over an hour now...

    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    No problem.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Unhappy Can I be a pest?

    I have tried the same method with radio buttons, but to no avail.

    The radio buttons are all called 'radio' but with different values, obviously...
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  6. #6
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    276
    If you had N radio buttons, U have to loop thro' them and find which of them is checked.

    for (i = 0; i < N; i++)
    {
    if (document.form.radio[i].checked == true)
    alert(document.form.radio[i].value);
    }

    - Jemima.

  7. #7

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Wink

    Thanks Jem,

    I'd forgotten all about the radio[i] property...

    It's been awhile..

    Hey, not meaning to be rude, but are you following me?

    You seem to be the one solving all my problems.

    Thanks!

    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  8. #8
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    for (i = 0; i < N; i++) {
    window.alert(document.form.<B>(checkbox + i)</B>.value)
    }
    just a quick point rjlohan, you can't but html tags in an alert box!

  9. #9
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    276
    oh boy! Did he mean
    for (i = 0; i < N; i++) {
    window.alert(document.form.(checkbox + i).value)
    } ?
    - Jemima.
    Last edited by JemimaChadwick; Oct 8th, 2001 at 03:50 AM.

  10. #10
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    276
    Jus a Mess!!! Pardon.

    - Jemima.

  11. #11

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    Yeah, I did Jem, sorry Bob, I'm not that that out of touch.
    I just used the wrong bracket when trying to highlight something for my post...
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

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