Array help!!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kenvin007@yahoo.com

    #1

    Array help!!

    Hi,
    Please help. Here is the situation. I've tried to create a radio button
    when clickeck by a user, a function will automatically check all
    checkbox in a form. I've tried to do this using a for loop but I did
    not have any luck.

    My intention was when a user click on the radio button, checkbox for
    testa,testb,tes tc,and testd will be checked.

    <form name="myForm">
    check all<input type="radio" name=alert value=all
    onclick="checkA ll(this)">
    <font color="oliveDra b" size=1%>testa </font><input
    type="checkbox" name=aix64testd value=aix64test d>
    <font color="oliveDra b" size=1%>presto </font><input
    type="checkbox" name=aix64testa value=aix64test a>
    <font color="oliveDra b" size=1%>psyn </font><input
    type="checkbox" name=aix64testb value=aix64test b>
    <font color="oliveDra b" size=1%>psynim </font><input
    type="checkbox" name=aix64testc value=aix64test c>

    <script type="text/javascript">

    function checkAll(Array1 ) {
    var myArr = new
    Array('aixtestd ','aix64testa', 'aix64testb','a ix64testc');
    for(var i; i<myArr.length; i++) {
    document.myForm .myArr['+i+']=true;
    }
    }
    <script>

    Thx, -Christie

  • kaeli

    #2
    Re: Array help!!

    In article <1112085426.537 519.11760@g14g2 000cwa.googlegr oups.com>, kenvin007
    @yahoo.com enlightened us with...[color=blue]
    > Hi,
    > My intention was when a user click on the radio button, checkbox for
    > testa,testb,tes tc,and testd will be checked.
    >
    > <form name="myForm">
    > check all<input type="radio" name=alert value=all
    > onclick="checkA ll(this)">[/color]

    Why are you sending the object to the function? It is not needed the way it
    is coded.
    [color=blue]
    > <script type="text/javascript">
    >
    > function checkAll(Array1 )[/color]

    You never reference Array1. If this is the full code, you can remove it.
    Don't forget that if you remove it from the call, you need to remove it from
    the function and vice versa.

    {[color=blue]
    > var myArr = new
    > Array('aixtestd ','aix64testa', 'aix64testb','a ix64testc');
    > for(var i; i<myArr.length; i++) {
    > document.myForm .myArr['+i+']=true;[/color]

    document.myForm .elements[myArr[i]].checked = true;

    Try that.
    Oh, and put attributes (like names and ids) in quotes. It can save a headache
    later if you do odd things like use brackets, spaces, or start the attributes
    with a number. i.e. checkbox name="aix64test a"

    Note: this is not at all how I'd code this sort of thing, but hey. :)

    --
    --
    ~kaeli~
    The more ridiculous a belief system, the higher probability
    of its success.



    Comment

    • tri.thanh.do@gmail.com

      #3
      Re: Array help!!


      kaeli wrote:[color=blue]
      > In article <1112085426.537 519.11760@g14g2 000cwa.googlegr oups.com>,[/color]
      kenvin007[color=blue]
      > @yahoo.com enlightened us with...[color=green]
      > > Hi,
      > > My intention was when a user click on the radio button, checkbox[/color][/color]
      for[color=blue][color=green]
      > > testa,testb,tes tc,and testd will be checked.
      > >
      > > <form name="myForm">
      > > check all<input type="radio" name=alert value=all
      > > onclick="checkA ll(this)">[/color]
      >
      > Why are you sending the object to the function? It is not needed the[/color]
      way it[color=blue]
      > is coded.
      >[color=green]
      > > <script type="text/javascript">
      > >
      > > function checkAll(Array1 )[/color]
      >
      > You never reference Array1. If this is the full code, you can remove[/color]
      it.[color=blue]
      > Don't forget that if you remove it from the call, you need to remove[/color]
      it from[color=blue]
      > the function and vice versa.
      >
      > {[color=green]
      > > var myArr = new
      > > Array('aixtestd ','aix64testa', 'aix64testb','a ix64testc');
      > > for(var i; i<myArr.length; i++) {
      > > document.myForm .myArr['+i+']=true;[/color]
      >
      > document.myForm .elements[myArr[i]].checked = true;
      >
      > Try that.
      > Oh, and put attributes (like names and ids) in quotes. It can save a[/color]
      headache[color=blue]
      > later if you do odd things like use brackets, spaces, or start the[/color]
      attributes[color=blue]
      > with a number. i.e. checkbox name="aix64test a"
      >
      > Note: this is not at all how I'd code this sort of thing, but hey.[/color]
      :)[color=blue]
      >
      > --
      > --
      > ~kaeli~
      > The more ridiculous a belief system, the higher probability
      > of its success.
      > http://www.ipwebdesign.net/wildAtHeart
      > http://www.ipwebdesign.net/kaelisSpace[/color]

      Comment

      Working...