Geoff,

Again, have you walked through with a decent debugger like Firebug and
actually inspected the form, the array, etc.?  That's really the only
thing that's going to do it.
--
T.J. Crowder
tj / crowder software / com

On Apr 19, 6:02 pm, geoffcox <[EMAIL PROTECTED]> wrote:
> I have changed to using true/false for the disabled attribute and am
> using
>
>   for (J=0;J<Next.length;++J){
>   F["B"+Next[J]].disabled = false;
>   DoSpecificTask[State](F);
>         }
>
> which comes up with "Next has no properties" on selecting either 10 or
> 11 in the last answer. I cannot see how to cope with this?!
>
> Cheers
>
> Geoff
>
> On Apr 19, 3:45 pm, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
>
> > Hi Geoff,
>
> > > I am not at all clear what I am iterating through?! Presumably through
> > > Next?
>
> > With the code you quoted, yes. Assuming 'Next' is an array with two
> > elements, 'J' will be 0 and then 1.  So if 'Next' is [7,8] (state 6 in
> > your list), then on the first pass J will be 0 and so Next[J] will be
> > 7, and then on the second pass J will be 1 and so Next[J] will be 8.
> > JavaScript arrays have a lot more to them than that, though, I'd
> > strongly recommend a read through the Arrays part of Chapter 3 of
> > JavaScript: The Definitive Guide by David Flanagan. [1]  In general,
> > in fact, that book rewards any time spent reading it with time-savings
> > down-the-line.
>
> > The best way to undestand what's happening with your code is to watch
> > it run in a debugger like Firebug.
>
> > On the code:  You seem to be setting the "disabled" property on form
> > fields to either "" or "disabled".  I'm pretty sure it's a boolean
> > property, you probably want to be using false (enabled) and true
> > (disabled).  Or use Prototype's disable() method. [2]
>
> > [1]http://www.oreilly.com/catalog/jscript5/
> > [2]http://www.prototypejs.org/api/form/element/disable
>
> > Hope this helps,
> > --
> > T.J. Crowder
> > tj / crowder software / com
>
> > On Apr 19, 1:29 pm, geoffcox <[EMAIL PROTECTED]> wrote:
>
> > > Thanks again...
>
> > > The nearest I can get is
>
> > >   for (J=0;J<Next.length;++J){
> > >   F["B"+Next[J]].disabled = ""
> > >   DoSpecificTask[State](F)
> > >   }
>
> > > which gives the first 3 answers but then the last one is
> > > undefined ...?
>
> > > I am not at all clear what I am iterating through?! Presumably through
> > > Next? One value of Next is 1,2 and presumably that means that
>
> > > B1 and B2 should be enabled? They are in fact. So why does this not
> > > work for the 4th answer, for B10 and B11?
>
> > > Any light on this?!
>
> > > Cheers
>
> > > Geoff
>
> > > On Apr 19, 12:20 pm, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
>
> > > > Geoff,
>
> > > > > but not sure how this works with the 2 dimensional array...
>
> > > > The array you're looping through with for..in isn't two-dimensional,
> > > > is it?  You're assigning Next to the sub-array (for lack of a better
> > > > term) within Arry, which is just one-dimensional (in fact, typically
> > > > single-element, although there are four of them that have two
> > > > elements).
>
> > > > > From the link you give I should use
>
> > > > > for (var index = 0; index < myArray.length; ++index)
> > > > > {   var item = myArray[index];
> > > > > F["B"+Next[J]].disabled = "";
> > > > > DoSpecificTask[State](F);
>
> > > > > }
>
> > > > > but not sure how this works with the 2 dimensional array...
>
> > > > > I've tried various permuations but ....
>
> > > > I'm guessing you weren't quoting actual code you'd tried?  That code
> > > > uses 'index' rather than 'J' as your index, uses 'myArray' instead of
> > > > 'Next', and assigns 'item' but never uses it.
>
> > > > Separately, it's worth pointing out that JavaScript doesn't have multi-
> > > > dimensional arrays.  It has arrays (which are really maps), and the
> > > > value of an element can be an array, but that's very different than
> > > > multi-dimensional arrays as in C, C++, and such.
>
> > > > Hope this helps,
> > > > --
> > > > T.J. Crowder
> > > > tj / crowder software / com
>
> > > > On Apr 19, 11:57 am, geoffcox <[EMAIL PROTECTED]> wrote:
>
> > > > > Hello,
>
> > > > > Thanks for you reply - I'm having problems getting the iteration to
> > > > > work. In fact not sure how to iterate in this case...
>
> > > > > From the link you give I should use
>
> > > > > for (var index = 0; index < myArray.length; ++index)
> > > > > {   var item = myArray[index];
> > > > > F["B"+Next[J]].disabled = "";
> > > > > DoSpecificTask[State](F);
>
> > > > > }
>
> > > > > but not sure how this works with the 2 dimensional array...
>
> > > > > I've tried various permuations but ....
>
> > > > > Help!
>
> > > > > Cheers
>
> > > > > Geoff
>
> > > > > On Apr 19, 10:53 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
>
> > > > > > Geoff,
>
> > > > > > My guess is it's the for..in that's doing you in.  Check out the 
> > > > > > docs
> > > > > > on Array
> > > > > > (http://www.prototypejs.org/api/array) and Enumerable
> > > > > > (http://www.prototypejs.org/api/enumerable)
> > > > > > for details.  For..in does not iterate the elements of an array; it
> > > > > > iterates the properties of an object.  These seem like the same 
> > > > > > thing
> > > > > > in some JavaScript implementations (but not all), but that stops
> > > > > > happening when Prototype adds its syntactic sugar to Array.
>
> > > > > > Separately:  You are relying quite heavily on semicolon insertion,
> > > > > > which can tend to obscure odd bugs.  It's best to always explicitly
> > > > > > use semicolons, never to rely on JavaScript to guess correctly where
> > > > > > they should go.  There are good maintainability reasons for this, as
> > > > > > well as the pragmatic reason that you pretty much can't use 
> > > > > > minimisers
> > > > > > on your code if you don't put semicolons in.
>
> > > > > > Hope this helps,
> > > > > > --
> > > > > > T.J. Crowder
> > > > > > tj / crowder software / com
>
> > > > > > On Apr 19, 8:49 am, geoffcox <[EMAIL PROTECTED]> wrote:
>
> > > > > > > Hello,
>
> > > > > > > Can anyone please see why as soon as add a link to prototype.js I 
> > > > > > > get
> > > > > > > an error message
>
> > > > > > > F["B" + Next[J]] has no properties
>
> > > > > > > I have tried changing the variable names but still get the error
> > > > > > > message.
>
> > > > > > > Help! Cheers Geoff
>
> > > > > > > var Arry = [
> > > > > > >   /* State 0 : */  [1,2],
> > > > > > >   /* State 1 : */  [3],
> > > > > > >   /* State 2 : */  [3],
> > > > > > >   /* State 3 : */  [4,5],
> > > > > > >   /* State 4 : */  [6],
> > > > > > >   /* State 5 : */  [6],
> > > > > > >   /* State 6 : */  [7,8],
> > > > > > >   /* State 7 : */  [9],
> > > > > > >   /* State 8 : */  [9],
> > > > > > >   /* State 9 : */  [10,11]]
>
> > > > > > > var result =new Array();
> > > > > > > var test_num=1;
> > > > > > > function A(f) {soundManager.play('mySound'+test_num 
> > > > > > > ,'../assets/audio-
> > > > > > > group1/Track' + (+test_num + 22) + '.mp3');  }
> > > > > > > function B(f) { result[test_num] = "same"; test_num++;}
> > > > > > > function C(f) { result[test_num] = "different";test_num++; }
>
> > > > > > > DoSpecificTask = [A, B, C, A, B, C, A, B, C, A, B, C]
>
> > > > > > > function Fn(Arg) {
> > > > > > >   var F = Arg.form, State, J, Next
> > > > > > >   State = Arg.value
> > > > > > >   for (J=0 ; J<12 ; J++) F["B"+J].disabled = "disabled"  // clear 
> > > > > > > all
> > > > > > >   Next = Arry[State]
> > > > > > >   for (J in Next) F["B"+Next[J]].disabled = ""          // set 
> > > > > > > some
> > > > > > >   DoSpecificTask[State](F)
>
> > > > > > >   }- Hide quoted text -
>
> > > > > > - Show quoted text -- Hide quoted text -
>
> > > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to rubyonrails-spinoffs@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to