logic and disabling onclicks?

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

    logic and disabling onclicks?

    Hello,

    I am not at clear how to tackle this one.

    Say the note middle C is played, just once.

    Then when the user clicks on a play image a series of notes are played
    starting with middle C and the user the user has to say whether the
    last sound is the same as the first or different. There are 4 sets of
    this.

    I can do this easily enough with 4 sets each with the play image and a
    same and different image. Call these A, B, C and D. The user clicks
    the play image to hear the series of sounds and then on either the
    same or the different image.

    The difficulty is in how to prevent the user, who when wondering about
    the answer to situation A, decides to click the play button for B to
    remind him/herself what the note C sounds like.

    So, after clicking the play image for A only the same and different
    images for A have their onclick events enabled. The play, same and
    different images for B, C and D have their onlicks disabled.

    On clicking the play image for B the only images for which the onclick
    event is enabled are the same and different images for B, etc etc .

    Any ideas please!?

    Cheers,

    Geoff
  • Dr J R Stockton

    #2
    Re: logic and disabling onclicks?

    In comp.lang.javas cript message <o1m804dtgo225f 9squr49dpa8mieu h80ke@4ax.
    com>, Tue, 15 Apr 2008 08:26:08, Geoff Cox <gcox@freeuk.no tcomposted:
    >
    >I have now got the code more general but cannot see how to prevent
    >user clicking the second, third or fourth play images whilst answering
    >the first test?
    You seem to have a disorderly approach.

    AIUI, you have a quantity of quasi-buttons, and restrictions on the
    sequence in which they may be used. Each set of restrictions needs to
    be held as an internal state. It may be, in your case, that the state
    is determined solely by which button was last pressed.

    It seems that, generally, most buttons should be disabled; so make
    undefined equivalent to off.

    Create an array, indexed by state 0..N, in which each element is itself
    an array of IDs of buttons to be allowed.

    var Arry = [
    /* State 0 : */ ["B1", "B2", "B3", "B4"],
    /* State 1 : */ ["B1", "B2"],
    // ...
    /* State N : */ ["B5", "B6"] ]

    In each Click event, determine the new State, and call a routine which
    disables all buttons and then enables the ones mentioned in the data for
    that State. It may simplify to have, for the first part, an array Btns
    naming all buttons.

    To change your Rules, you now merely have to alter the literal assigned
    to A.

    function X(State) { var J, D = Arr[State]
    for (J in Btns) { } // disable Btns[J]
    for (J in Arry) { } // enable Arry[J]
    }


    I think you could possibly save time (irrelevantly) by creating
    at the start an Object indexed by the button IDs holding the
    results of getElementById( ID).

    You can test that out with a dummy system consisting of ordinary buttons
    and reporting on its innards each time.

    --
    (c) John Stockton, nr London UK. ?@merlyn.demon. co.uk BP7, Delphi 3 & 2006.
    <URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/&c., FAQqy topics & links;
    <URL:http://www.bancoems.co m/CompLangPascalD elphiMisc-MiniFAQ.htmclpd mFAQ;
    <URL:http://www.borland.com/newsgroups/guide.htmlnews: borland.* Guidelines

    Comment

    • Geoff Cox

      #3
      Re: logic and disabling onclicks?

      On Tue, 15 Apr 2008 20:43:50 +0100, Dr J R Stockton
      <jrs@merlyn.dem on.co.ukwrote:
      >In comp.lang.javas cript message <o1m804dtgo225f 9squr49dpa8mieu h80ke@4ax.
      >com>, Tue, 15 Apr 2008 08:26:08, Geoff Cox <gcox@freeuk.no tcomposted:
      >>
      >>I have now got the code more general but cannot see how to prevent
      >>user clicking the second, third or fourth play images whilst answering
      >>the first test?
      >
      >You seem to have a disorderly approach.
      ...that I must agree with! I am moving along on a wing and a prayer ...
      will give some thought now to your suggestions. Thanks.

      Geoff
      >
      >AIUI, you have a quantity of quasi-buttons, and restrictions on the
      >sequence in which they may be used. Each set of restrictions needs to
      >be held as an internal state. It may be, in your case, that the state
      >is determined solely by which button was last pressed.
      >
      >It seems that, generally, most buttons should be disabled; so make
      >undefined equivalent to off.
      >
      >Create an array, indexed by state 0..N, in which each element is itself
      >an array of IDs of buttons to be allowed.
      >
      >var Arry = [
      >/* State 0 : */ ["B1", "B2", "B3", "B4"],
      >/* State 1 : */ ["B1", "B2"],
      >// ...
      >/* State N : */ ["B5", "B6"] ]
      >
      >In each Click event, determine the new State, and call a routine which
      >disables all buttons and then enables the ones mentioned in the data for
      >that State. It may simplify to have, for the first part, an array Btns
      >naming all buttons.
      >
      >To change your Rules, you now merely have to alter the literal assigned
      >to A.
      >
      >function X(State) { var J, D = Arr[State]
      for (J in Btns) { } // disable Btns[J]
      for (J in Arry) { } // enable Arry[J]
      }
      >
      >
      I think you could possibly save time (irrelevantly) by creating
      at the start an Object indexed by the button IDs holding the
      results of getElementById( ID).
      >
      >You can test that out with a dummy system consisting of ordinary buttons
      >and reporting on its innards each time.

      Comment

      • Dr J R Stockton

        #4
        Re: logic and disabling onclicks?

        In comp.lang.javas cript message <hn4b04dp2ajt4d r5gmlmsc2dqgabd pth2f@4ax.
        com>, Wed, 16 Apr 2008 06:53:19, Geoff Cox <gcox@freeuk.no tcomposted:
        >
        >I cannot see how to get going using your suggestions!
        >
        >Any chance that you can point me at any code using your suggested
        >approach? That might get me started on that route.
        This is much as I suggested, except that all controls call a single
        handler, Fn, which after handling the Enables calls the main routines
        represented by A B C. The buttons could equally well call individual
        handlers which each initially call Fn without its last statement.
        Tested IE7, FF2, Op9, Sf3, OK : does not pass W3 TIDY, due to omissions.

        But it does not correspond exactly with what I wrote before; there are
        various similar ways, of similar merit, of doing the job.


        <form>
        <input type=button name="B0" value=0 onClick="Fn(thi s)">
        <input type=button name="B1" value=1 onClick="Fn(thi s)">
        <input type=button name="B2" value=2 onClick="Fn(thi s)">
        <input type=button name="B3" value=3 onClick="Fn(thi s)">
        <input type=button name="B4" value=4 onClick="Fn(thi s)">
        <input type=button name="B5" value=5 onClick="Fn(thi s)">
        <input type=button name="B6" value=6 onClick="Fn(thi s)">
        <input type=button name="B7" value=7 onClick="Fn(thi s)">
        <br>
        State, Result : <input type=text name=S>
        </form>

        <script>

        var Arry = [
        /* State 0 : */ [0, 1, 2, 3],
        /* State 1 : */ [2],
        /* State 2 : */ [3],
        /* State 3 : */ [4],
        /* State 4 : */ [5, 6, 7],
        /* State 5 : */ [6, 2],
        /* State 6 : */ [7, 2],
        /* State 7 : */ [0] ]

        function A(f) { f.S.value += ", Hay" }
        function B(f) { f.S.value += ", Bee" }
        function C(f) { f.S.value += ", Sea" }
        function Z(f) { f.S.value += ", Zed" }

        DoSpecificTask = [A, B, C, B, A, B, C, Z]

        function Fn(Arg) { var F = Arg.form, State, J, Next
        F.S.value = State = Arg.value // or = Func(Arg.value, State)
        for (J=0 ; J<8 ; 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) }

        </script>


        Modify the indicated part if the State depends on more than which button
        was pressed last.

        For test, choose if possible Opera or Safari, because the buttons look
        nicer there.

        --
        (c) John Stockton, nr London UK. ?@merlyn.demon. co.uk Turnpike v6.05 MIME.
        <URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/&c., FAQqy topics & links;
        <URL:http://www.merlyn.demo n.co.uk/clpb-faq.txt RAH Prins : c.l.p.b mFAQ;
        <URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zipTimo Salmi's Turbo Pascal FAQ.

        Comment

        • Geoff Cox

          #5
          Re: logic and disabling onclicks?

          On Wed, 16 Apr 2008 23:34:10 +0100, Dr J R Stockton
          <jrs@merlyn.dem on.co.ukwrote:
          >In comp.lang.javas cript message <hn4b04dp2ajt4d r5gmlmsc2dqgabd pth2f@4ax.
          >com>, Wed, 16 Apr 2008 06:53:19, Geoff Cox <gcox@freeuk.no tcomposted:
          >>
          >>I cannot see how to get going using your suggestions!
          >>
          >>Any chance that you can point me at any code using your suggested
          >>approach? That might get me started on that route.
          >
          >This is much as I suggested, except that all controls call a single
          >handler, Fn, which after handling the Enables calls the main routines
          >represented by A B C. The buttons could equally well call individual
          >handlers which each initially call Fn without its last statement.
          >Tested IE7, FF2, Op9, Sf3, OK : does not pass W3 TIDY, due to omissions.
          >
          >But it does not correspond exactly with what I wrote before; there are
          >various similar ways, of similar merit, of doing the job.
          Sorry for slow response - I have only just seen your reply - will read
          carefully and try again!

          Cheers

          Geoff

          >
          >
          ><form>
          ><input type=button name="B0" value=0 onClick="Fn(thi s)">
          ><input type=button name="B1" value=1 onClick="Fn(thi s)">
          ><input type=button name="B2" value=2 onClick="Fn(thi s)">
          ><input type=button name="B3" value=3 onClick="Fn(thi s)">
          ><input type=button name="B4" value=4 onClick="Fn(thi s)">
          ><input type=button name="B5" value=5 onClick="Fn(thi s)">
          ><input type=button name="B6" value=6 onClick="Fn(thi s)">
          ><input type=button name="B7" value=7 onClick="Fn(thi s)">
          ><br>
          >State, Result : <input type=text name=S>
          ></form>
          >
          ><script>
          >
          >var Arry = [
          /* State 0 : */ [0, 1, 2, 3],
          /* State 1 : */ [2],
          /* State 2 : */ [3],
          /* State 3 : */ [4],
          /* State 4 : */ [5, 6, 7],
          /* State 5 : */ [6, 2],
          /* State 6 : */ [7, 2],
          /* State 7 : */ [0] ]
          >
          >function A(f) { f.S.value += ", Hay" }
          >function B(f) { f.S.value += ", Bee" }
          >function C(f) { f.S.value += ", Sea" }
          >function Z(f) { f.S.value += ", Zed" }
          >
          >DoSpecificTa sk = [A, B, C, B, A, B, C, Z]
          >
          >function Fn(Arg) { var F = Arg.form, State, J, Next
          F.S.value = State = Arg.value // or = Func(Arg.value, State)
          for (J=0 ; J<8 ; 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) }
          >
          ></script>
          >
          >
          >Modify the indicated part if the State depends on more than which button
          >was pressed last.
          >
          >For test, choose if possible Opera or Safari, because the buttons look
          >nicer there.

          Comment

          • Geoff Cox

            #6
            Re: logic and disabling onclicks?

            On Wed, 16 Apr 2008 23:34:10 +0100, Dr J R Stockton
            <jrs@merlyn.dem on.co.ukwrote:

            John,

            I have got a little further with the code below which shows my 4 sets,
            each containing a button plus the 2 options.

            The 2 options to be "same" and "different" depending on whether the
            user thinks the last sound of the series of sounds played by the
            button is the same or different from the first sound

            So far not clear how for example I associate the playing of a series
            of sounds with the first button?

            I need to have the following work once the first button is clicked, (t
            being equal to say, 1, the first of the 4 sets)

            soundManager.pl ay('mySound'+t ,'../assets/audio-group1/Track' + (+t +
            22) + '.mp3');

            How do I do this?

            Thanks,

            Geoff

            <script>

            var Arry = [
            /* State 0 : */ [1, 2],
            /* State 1 : */ [0],
            /* State 2 : */ [0],
            /* State 3 : */ [4, 5],
            /* State 4 : */ [3],
            /* State 5 : */ [3],
            /* State 6 : */ [7, 8],
            /* State 7 : */ [6],
            /* State 8 : */ [6],
            /* State 9 : */ [10, 11],
            /* State 10 : */ [9],
            /* State 11 : */ [9] ]

            function A(f) { f.S.value += ", Hay" }
            function B(f) { f.S.value += ", Bee" }
            function C(f) { f.S.value += ", Sea" }
            function D(f) { f.S.value += ", Land" }
            function E(f) { f.S.value += ", Hill" }
            function F(f) { f.S.value += ", Hill side" }
            function Z(f) { f.S.value += ", Zed" }

            DoSpecificTask = [A, B, C, D, E, F, B, A, B, C, D, Z]

            function Fn(Arg) { var F = Arg.form, State, J, Next
            F.S.value = State = Arg.value // or = Func(Arg.value, State)
            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) }

            </script>


            </head>

            <body>


            <form>
            <input type=button style=backgroun d-color:#00ffff name="B0" value=0
            onClick="Fn(thi s)">
            <input type=button name="B1" value=1 onClick="Fn(thi s)">
            <input type=button name="B2" value=2 onClick="Fn(thi s)"><br>

            <input type=button style=backgroun d-color:#00ffff name="B3" value=3
            onClick="Fn(thi s)">
            <input type=button name="B4" value=4 onClick="Fn(thi s)">
            <input type=button name="B5" value=5 onClick="Fn(thi s)"><br>

            <input type=button style=backgroun d-color:#00ffff name="B6" value=6
            onClick="Fn(thi s)">
            <input type=button name="B7" value=7 onClick="Fn(thi s)">
            <input type=button name="B8" value=8 onClick="Fn(thi s)"><br>

            <input type=button style=backgroun d-color:#00ffff name="B9" value=9
            onClick="Fn(thi s)">
            <input type=button name="B10" value=10 onClick="Fn(thi s)">
            <input type=button name="B11" value=11 onClick="Fn(thi s)">
            <br>
            State, Result : <input type=text name=S>
            </form>

            Comment

            • Geoff Cox

              #7
              Re: logic and disabling onclicks?

              On Fri, 18 Apr 2008 08:32:49 +0100, Geoff Cox <gcox@freeuk.no tcom>
              wrote:

              John,

              I think there was a typo in my previous posting - but the code below
              works apart from knowing how to run the soundManager code ...

              Cheers

              Geoff


              <script>

              var Arry = [
              /* State 0 : */ [1, 2],
              /* State 1 : */ [0],
              /* State 2 : */ [0],
              /* State 3 : */ [4, 5],
              /* State 4 : */ [3],
              /* State 5 : */ [3],
              /* State 6 : */ [7, 8],
              /* State 7 : */ [6],
              /* State 8 : */ [6],
              /* State 9 : */ [10, 11],
              /* State 10 : */ [9],
              /* State 11 : */ [9] ]

              function A(f) { f.S.value += ", Hay" }
              function B(f) { f.S.value += ", Bee" }
              function C(f) { f.S.value += ", Sea" }
              function Z(f) { f.S.value += ", Zed" }

              DoSpecificTask = [A, B, C, B, A, B, C, B, A, B, A, Z]

              function Fn(Arg) { var F = Arg.form, State, J, Next
              F.S.value = State = Arg.value // or = Func(Arg.value, State)
              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) }

              </script>


              </head>

              <body>


              <form>
              <input style=backgroun d-color:#00ffff type=button name="B0" value=0
              onClick="Fn(thi s)">
              <input type=button name="B1" value=1 onClick="Fn(thi s)">
              <input type=button name="B2" value=2 onClick="Fn(thi s)"><br>
              <input style=backgroun d-color:#00ffff type=button name="B3" value=3
              onClick="Fn(thi s)">
              <input type=button name="B4" value=4 onClick="Fn(thi s)">
              <input type=button name="B5" value=5 onClick="Fn(thi s)"><br>
              <input style=backgroun d-color:#00ffff type=button name="B6" value=6
              onClick="Fn(thi s)">
              <input type=button name="B7" value=7 onClick="Fn(thi s)">
              <input type=button name="B8" value=8 onClick="Fn(thi s)"><br>
              <input style=backgroun d-color:#00ffff type=button name="B9" value=9
              onClick="Fn(thi s)">
              <input type=button name="B10" value=10 onClick="Fn(thi s)">
              <input type=button name="B11" value=11 onClick="Fn(thi s)">
              <br>
              State, Result : <input type=text name=S>
              </form>

              Comment

              • Geoff Cox

                #8
                Re: logic and disabling onclicks?

                On Wed, 16 Apr 2008 23:34:10 +0100, Dr J R Stockton
                <jrs@merlyn.dem on.co.ukwrote:


                John,

                I cannot udnerstand this - as soon as I add a link to the prototype.js
                javascript library to the code that works shown in previous post - I
                get error message "F["B" + Next[J]] has no properties".

                Any idea why would this be?

                Cheers

                Geoff

                Comment

                • Geoff Cox

                  #9
                  Re: logic and disabling onclicks?

                  On Wed, 16 Apr 2008 23:34:10 +0100, Dr J R Stockton
                  <jrs@merlyn.dem on.co.ukwrote:


                  Jon,

                  Even more success!

                  I can now run some functions

                  var result = new Array();
                  var test_num = 1;

                  function A(f) {soundManager.p lay('mySound1'
                  ,'../assets/audio-group1/Track23' + '.mp3'); }

                  function B(f) { result[test_num] = "same";
                  alert(result[test_num]);test_num++;}

                  function C(f) { result[test_num] =
                  "different";ale rt(result[test_num]);test_num++; }


                  DoSpecificTask = [A, B, C, A, B, C, A, B, C, A, B, C]

                  A couple of unsolved items.

                  1. At the moment after selecting button 0 only buttons 1 and 2 are
                  enabled - this is fine but to enable the next set, 3, 4 and 5 I am
                  having to refresh the page and so the test_num++ doesn't work.

                  Can I enable 3, 4 and 5 and disable the following

                  0, 1 and 2
                  6, 7 and 8
                  9, 10 and 11

                  without having to refresh the page?

                  2. still get the error message when I add the link to prototype.js,

                  <script src="../assets/javascripts/prototype.js"
                  type="text/javascript"></script>

                  Is there a conflict between your code and something in the
                  prototype.js?!

                  Cheers

                  Geoff

                  Comment

                  • Geoff Cox

                    #10
                    Re: logic and disabling onclicks?

                    On Wed, 16 Apr 2008 23:34:10 +0100, Dr J R Stockton
                    <jrs@merlyn.dem on.co.ukwrote:

                    John,

                    I think I have finally got there!

                    The folowing code works fine. Just a few points

                    1. I still get the error message if I add the link to prototype.js -
                    any idea why?

                    2. the buttons are name B0, B1, B2 etc and I need to have Play, Same
                    and Different ... can I do this?

                    3. Is it possible to go back to using images rather than buttons?

                    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.p lay('mySound'+t est_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";tes t_num++; }
                    function Z(f) { f.S.value += ", Zed" }

                    DoSpecificTask = [A, B, C, A, B, C, A, B, C, A, B, C]

                    function Fn(Arg) {
                    var F = Arg.form, State, J, Next
                    //F.S.value = State = Arg.value // or = Func(Arg.value,
                    State)
                    State = Arg.value // or = Func(Arg.value, State)
                    for (J=0 ; J<12 ; J++) F["B"+J].disabled = "disabled" // clear all
                    //alert('State = ' + State);
                    Next = Arry[State]
                    //alert('Next = ' + Next);
                    for (J in Next) F["B"+Next[J]].disabled = "" // set some
                    DoSpecificTask[State](F)

                    }

                    function disableAllExcep tFirst() {

                    }

                    function getResults() {
                    for (var i=1;i<5;i++) {
                    alert(result[i]);
                    }
                    }

                    </script>


                    </head>

                    <body onLoad="disable AllExceptFirst( );">


                    <form name ="form1">
                    <input style=backgroun d-color:#00ffff type=button name="B0" value=0
                    onClick="Fn(thi s)">
                    <input type=button name="B1" value=1 onClick="Fn(thi s)"
                    disabled="disab led">
                    <input type=button name="B2" value=2 onClick="Fn(thi s)"
                    disabled="disab led"><br>
                    <input style=backgroun d-color:#00ffff type=button name="B3" value=3
                    onClick="Fn(thi s)" disabled="disab led">
                    <input type=button name="B4" value=4 onClick="Fn(thi s)"
                    disabled="disab led">
                    <input type=button name="B5" value=5 onClick="Fn(thi s)"
                    disabled="disab led"><br>
                    <input style=backgroun d-color:#00ffff type=button name="B6" value=6
                    onClick="Fn(thi s)" disabled="disab led">
                    <input type=button name="B7" value=7 onClick="Fn(thi s)"
                    disabled="disab led">
                    <input type=button name="B8" value=8 onClick="Fn(thi s)"
                    disabled="disab led"><br>
                    <input style=backgroun d-color:#00ffff type=button name="B9" value=9
                    onClick="Fn(thi s)" disabled="disab led">
                    <input type=button name="B10" value=10 onClick="Fn(thi s)"
                    disabled="disab led">
                    <input type=button name="B11" value=11 onClick="Fn(thi s)"
                    disabled="disab led">
                    <br>

                    </form>

                    <input type = "button" value = "get results" onClick="getRes ults();">
                    <div></div>

                    Comment

                    • Dr J R Stockton

                      #11
                      Re: logic and disabling onclicks?

                      In comp.lang.javas cript message <58mg0413v7n7n3 mpju7pbopqfheg5 97t4k@4ax.
                      com>, Fri, 18 Apr 2008 09:18:15, Geoff Cox <gcox@freeuk.no tcomposted:
                      >
                      >I think there was a typo in my previous posting - but the code below
                      >works apart from knowing how to run the soundManager code ...
                      >
                      I don't do sound.

                      --
                      (c) John Stockton, nr London, UK. ?@merlyn.demon. co.uk Turnpike v6.05 MIME.
                      Web <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.
                      Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
                      Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)

                      Comment

                      • Dr J R Stockton

                        #12
                        Re: logic and disabling onclicks?

                        In comp.lang.javas cript message <o2bh04l112eko0 q8rmliu05q6ciru phomd@4ax.
                        com>, Fri, 18 Apr 2008 15:21:21, Geoff Cox <gcox@freeuk.no tcomposted:
                        >On Wed, 16 Apr 2008 23:34:10 +0100, Dr J R Stockton
                        ><jrs@merlyn.de mon.co.ukwrote:
                        >
                        >
                        >Jon,
                        >
                        >Even more success!
                        >
                        >I can now run some functions
                        >
                        >var result = new Array();
                        >var test_num = 1;
                        >
                        >function A(f) {soundManager.p lay('mySound1'
                        >,'../assets/audio-group1/Track23' + '.mp3'); }
                        >
                        >function B(f) { result[test_num] = "same";
                        >alert(result[test_num]);test_num++;}
                        >
                        >function C(f) { result[test_num] =
                        >"different";al ert(result[test_num]);test_num++; }
                        >
                        >
                        >DoSpecificTa sk = [A, B, C, A, B, C, A, B, C, A, B, C]
                        >
                        >A couple of unsolved items.
                        >
                        >1. At the moment after selecting button 0 only buttons 1 and 2 are
                        >enabled - this is fine but to enable the next set, 3, 4 and 5 I am
                        >having to refresh the page and so the test_num++ doesn't work.
                        You need to alter the content of Arry to suit what you want to allow.
                        >Can I enable 3, 4 and 5 and disable the following
                        >
                        >0, 1 and 2
                        >6, 7 and 8
                        >9, 10 and 11
                        >
                        >without having to refresh the page?
                        Yes.
                        >2. still get the error message when I add the link to prototype.js,
                        >
                        ><script src="../assets/javascripts/prototype.js"
                        >type="text/javascript"></script>
                        >
                        >Is there a conflict between your code and something in the
                        >prototype.js ?!
                        Quite likely; I don't use prototype.js. If the debugging facilities in
                        your browsers do not help, try renaming any variables which might
                        conflict - it sometimes solves a problem of that nature.

                        --
                        (c) John Stockton, nr London UK. ?@merlyn.demon. co.uk BP7, Delphi 3 & 2006.
                        <URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/&c., FAQqy topics & links;
                        <URL:http://www.bancoems.co m/CompLangPascalD elphiMisc-MiniFAQ.htmclpd mFAQ;
                        <URL:http://www.borland.com/newsgroups/guide.htmlnews: borland.* Guidelines

                        Comment

                        • Geoff Cox

                          #13
                          Re: logic and disabling onclicks?

                          On Fri, 18 Apr 2008 19:33:51 +0100, Dr J R Stockton
                          <jrs@merlyn.dem on.co.ukwrote:


                          John,

                          I think have found the reason why your code conflicts with
                          prototype.js.

                          You have

                          for (J in Next) F["B"+Next[J]].disabled = "" // set some
                          DoSpecificTask[State](F)

                          Apparently in some implementations of Javascript this iteration
                          applies to the properties of an object rather than the elements
                          (someone in the prototype forum).

                          Certainly if I change to

                          for (J=0;J<Next.len gth;++J){
                          F["B"+Next[J]].disabled = false;
                          }

                          the problem with prototype.js goes but I still haven't got it right as
                          on clicking the last answer I get an the error message

                          Next has no properties.

                          Can you see why?!

                          Cheers

                          Geoff

                          Comment

                          • Geoff Cox

                            #14
                            Re: logic and disabling onclicks?

                            On Fri, 18 Apr 2008 19:33:51 +0100, Dr J R Stockton
                            <jrs@merlyn.dem on.co.ukwrote:

                            John,

                            Re the conflict with prototype.js - the problem being the use of
                            for/in to iterate over the Next values...

                            I should have written

                            for (J=0;J<Next.len gth;++J){
                            F["B"+Next[J]].disabled = false;
                            DoSpecificTask[State](F);
                            }

                            This comes up with Next has no properties on answering the 4th
                            question. Can you see why?! Is there a better non-for/in way of
                            iteration to avoid the conflict with prototype.js?

                            Cheers

                            Geoff

                            Comment

                            • Dr J R Stockton

                              #15
                              Re: logic and disabling onclicks?

                              In comp.lang.javas cript message <qt2i04lm2rq2tv fqoqo9aespbs411 5ep4o@4ax.
                              com>, Fri, 18 Apr 2008 22:02:44, Geoff Cox <gcox@freeuk.no tcomposted:
                              >On Wed, 16 Apr 2008 23:34:10 +0100, Dr J R Stockton
                              ><jrs@merlyn.de mon.co.ukwrote:
                              >The folowing code works fine. Just a few points
                              >
                              >1. I still get the error message if I add the link to prototype.js -
                              >any idea why?
                              Only as I said before. I know nothing of prototype.js - and that's only
                              a file name, there may be quite different ones.

                              >2. the buttons are name B0, B1, B2 etc and I need to have Play, Same
                              >and Different ... can I do this?
                              For convenience in constructing the names, I chose the form B-Number.
                              You can change that, but it will then be more work to address them. But
                              it is the values of the buttons, not the names, that the user will see.
                              You could put the names of the buttons, instead of numbers, in Arry.

                              >3. Is it possible to go back to using images rather than buttons?
                              Doubtless. If images can be disabled for receiving clicks, little will
                              need to be changed. If not, you can put code within the response
                              function(s) to see whether the present state allows that image to
                              "work", and just return if not (possibly also writing "CHEAT" or "OK"
                              somewhere on-screen).

                              The purpose of my posting that code was not to provide a Final Solution,
                              but to show how the routing structure could be compactly represented.

                              --
                              (c) John Stockton, nr London, UK. ?@merlyn.demon. co.uk Turnpike v6.05 MIME.
                              Web <URL:http://www.merlyn.demo n.co.uk/- FAQqish topics, acronyms & links;
                              Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
                              No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

                              Comment

                              Working...