better ways?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Draken

    better ways?

    I have a menu of radio buttons with the name myform (thank you to Evertjan.
    for your help with my other problem, I have no idea where the error was but
    I worked through it from your advice) pretty much one of them HAS to be
    selected (it would be hard to avoid it) and my loop cycles through until if
    finds the checked button... as I have no way to tell how many items there
    will be in the array of menu items I cant put a static number in the loop,
    at the moment I have this....
    for(i=0;documen t.menuform.myfo rm[i] != undefined;i++)

    as when you reach say document.menufo rm.myform[10] and there is no 10th it
    will return "undefined" , but this doesnt seem to be the best of ways to do
    it? Is there any exceptions to this way? Any better ways? I tried while
    (document.menuf orm.myform) thinking that reaching an undefined item would be
    'false' but as you can guess i caused an infinite loop :(

    So basically is there any better/easier ways to write this loop, and are
    there any exceptions to this loop?
    Thanks


  • Markus Ernst

    #2
    Re: better ways?


    "Draken" <lord_draken_ko [email protected] > schrieb im Newsbeitrag
    news:3f03f83b$0 [email protected] ...[color=blue]
    > I have a menu of radio buttons with the name myform (thank you to[/color]
    Evertjan.[color=blue]
    > for your help with my other problem, I have no idea where the error was[/color]
    but[color=blue]
    > I worked through it from your advice) pretty much one of them HAS to be
    > selected (it would be hard to avoid it) and my loop cycles through until[/color]
    if[color=blue]
    > finds the checked button... as I have no way to tell how many items there
    > will be in the array of menu items I cant put a static number in the loop,
    > at the moment I have this....
    > for(i=0;documen t.menuform.myfo rm[i] != undefined;i++)
    >
    > as when you reach say document.menufo rm.myform[10] and there is no 10th it
    > will return "undefined" , but this doesnt seem to be the best of ways to do
    > it? Is there any exceptions to this way? Any better ways? I tried while
    > (document.menuf orm.myform) thinking that reaching an undefined item would[/color]
    be[color=blue]
    > 'false' but as you can guess i caused an infinite loop :(
    >
    > So basically is there any better/easier ways to write this loop, and are
    > there any exceptions to this loop?
    > Thanks
    >
    >[/color]

    for(i=0; i<document.menu form.myform.len gth; i++)

    --
    Markus


    Comment

    • Fred Serry

      #3
      Re: better ways?


      "Richard Cornford" <Richard@litote s.demon.co.uk> schreef in bericht
      news:be14m6$hrq $1$8302bc10@new s.demon.co.uk.. .[color=blue]
      > "Fred Serry" <fred.serry.rem [email protected]> wrote in message
      > news:be0vq1$l5m [email protected] cis.de...
      > <snip>
      >
      > Did you get that one backwards?
      >[color=green]
      > > for(i=0;i<docum ent.menuform.my form.elements.l ength;i++)[/color]
      >
      > for(i=0;i<docum ent.menuform.el ements.myform.l ength;i++)
      >
      > ("myform" seems a misleading name to give to a set of radio buttons)
      >
      > Richard.
      >
      >[/color]

      Holidays starts tomorrow. Seems I need it :)


      Comment

      • Draken

        #4
        Re: better ways?

        > ("myform" seems a misleading name to give to a set of radio buttons)[color=blue]
        > Richard.[/color]

        Not sure if that is backwards, I didnt use it as the elements section isnt
        needed. I called it myform simply because I had help in a different thread
        called "help with onClick" or something like that and I copied and pasted
        the code of a working example and didnt change anything, of course I could
        change it, but I dont need to, its for a personal website and im the only
        person who needs to understand it. The form used to be called menu... which
        is a better name for the radio buttons which make up a menu, but I didnt use
        that again incase that was some sort of reserved word that was causing an
        error.

        my only question is the operator... shouldn't it be i<= .. rather than just
        < ?? cause if I have 10 array items doesnt the < operator stop at 9?



        Comment

        • Markus Ernst

          #5
          Re: better ways?

          if i starts at 0 you have 10 values that are < 10, that's the trick...

          --
          Markus

          [color=blue]
          > my only question is the operator... shouldn't it be i<= .. rather than[/color]
          just[color=blue]
          > < ?? cause if I have 10 array items doesnt the < operator stop at 9?
          >
          >
          >[/color]


          Comment

          Working...