SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Wishful Thinking webmasternovis's Avatar
    Join Date
    Jul 2002
    Location
    England
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Accessing radio/check boxes

    Hi all,

    To alter the data in an input box I'm using the following code:

    Code:
    var EsMiles = "estimatedmiles" + theload;
    document.calform.estimatedmiles1.value = document.calform[EsMiles].value;
    "theload" holds a digit which refers to which input box I want to edit - so EsMiles is the full name of this input box.

    However, this won't work for radio and checkboxes. I'm trying to use this:

    Code:
    var foc = "flatorcwt" + theload;
    if (document.calform[foc[1]].checked==true)
    {
    document.calform.flatorcwt2[1].checked=true;
    }
    The [1] is which element of the radio box I want altered. As I said, this won't work and I get an error.

    Does anybody know how I could achieve this for radio boxes and checkboxes?

    Thanks,
    Mike

  2. #2
    Wishful Thinking webmasternovis's Avatar
    Join Date
    Jul 2002
    Location
    England
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone have any ideas?

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    You can access the named elements with the following

    Code javascript:
    var foc = document.getElementsByName("myName" + theload);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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