SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get to get check value in an array

    Hi

    On my form I have an array of checkboxes
    In the javascript code I need to find out which checkbox was selected and then removed checkmarks from some others.
    I don't seem to be getting anywhere with my code.

    <td><input class='checkbox' type='checkbox' name='Selected1[]' value='$sSelected1[]' onchange='javascript:iCheckBoxSelected();'></td>


    function iCheckBoxSelected()
    {
    var chk_arr = document.getElementsByName("Selected1[]");

    for (iCount=0; iCount < 3; iCount++)
    {
    if (chk_arr[iCheckboxNum].checked == 1)
    {
    alert ("do something here");
    }
    }


    }

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by kath View Post
    On my form I have an array of checkboxes
    In the javascript code I need to find out which checkbox was selected and then removed checkmarks from some others.
    I don't seem to be getting anywhere with my code.
    Are you wanting only one checkbox to be active at a time? Because if so - radio buttons are the best interface for that type of situation.

    If your situation is different though, can we get some details about what you are wanting to achieve with the checkboxes?
    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
  •