SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Checkbox name

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checkbox name

    My Javascript works if the name of the checkboxes is written in the following way:

    <input type=checkbox name=cbPick1>
    <input type=checkbox name=cbPick2> and so on.

    However, I need to change it to:

    <input type=checkbox name=cbPick[1]>
    <input type=checkbox name=cbPick[2]>, because my PHP scripts are written to understand in this way.

    I wonder how I should change the following Javascript so that it understands cbPick[1] instead of cbPick1:


    function SelectNumber(number)
    {
    var IsChecked = 0;
    if (!document.lot["cbPick" + number])
    { return; }
    for( j=1;j<number;j++)
    {
    if (document.lot["cbPick" + j].checked)
    {
    continue;
    }
    document.lot["cbPick" + j].checked =1;
    document.lot["cbPick" + j].checked =0;
    }
    document.lot["cbPick" + j].checked=1;
    Refresh();
    }

    function QuickPick()
    {
    ClearBoard()
    var MaxNumber = "7";
    var HiNumber = 40 - 1;
    var Number = 0;
    while ( Number < MaxNumber )
    {
    var number = (Math.random() * HiNumber) + 1;
    number = Math.round(number);
    if (!document.lot["cbPick" + number].checked)
    {
    SelectNumber(number);
    Number++;
    }
    }
    }


    Thank you.

  2. #2
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,121
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Personally, I'd change your PHP scripts, they are far more flexible then JS. []'s are not standard characters so are probably throwing your JS so far off (add to that that they are reserved characters for arrays and you've got double-trouble).
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright


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
  •