473,386 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Jun 27 '08 #1
20 1234
In comp.lang.javascript message <o1m804dtgo225f9squr49dpa8mieuh80ke@4ax.
com>, Tue, 15 Apr 2008 08:26:08, Geoff Cox <gc**@freeuk.notcomposted:
>
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.demon.co.uk/TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htmclpdmFAQ;
<URL:http://www.borland.com/newsgroups/guide.htmlnews:borland.* Guidelines
Jun 27 '08 #2
On Tue, 15 Apr 2008 20:43:50 +0100, Dr J R Stockton
<jr*@merlyn.demon.co.ukwrote:
>In comp.lang.javascript message <o1m804dtgo225f9squr49dpa8mieuh80ke@4ax.
com>, Tue, 15 Apr 2008 08:26:08, Geoff Cox <gc**@freeuk.notcomposted:
>>
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.
Jun 27 '08 #3
In comp.lang.javascript message <hn4b04dp2ajt4dr5gmlmsc2dqgabdpth2f@4ax.
com>, Wed, 16 Apr 2008 06:53:19, Geoff Cox <gc**@freeuk.notcomposted:
>
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(this)">
<input type=button name="B1" value=1 onClick="Fn(this)">
<input type=button name="B2" value=2 onClick="Fn(this)">
<input type=button name="B3" value=3 onClick="Fn(this)">
<input type=button name="B4" value=4 onClick="Fn(this)">
<input type=button name="B5" value=5 onClick="Fn(this)">
<input type=button name="B6" value=6 onClick="Fn(this)">
<input type=button name="B7" value=7 onClick="Fn(this)">
<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.demon.co.uk/TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.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.
Jun 27 '08 #4
On Wed, 16 Apr 2008 23:34:10 +0100, Dr J R Stockton
<jr*@merlyn.demon.co.ukwrote:
>In comp.lang.javascript message <hn4b04dp2ajt4dr5gmlmsc2dqgabdpth2f@4ax.
com>, Wed, 16 Apr 2008 06:53:19, Geoff Cox <gc**@freeuk.notcomposted:
>>
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(this)">
<input type=button name="B1" value=1 onClick="Fn(this)">
<input type=button name="B2" value=2 onClick="Fn(this)">
<input type=button name="B3" value=3 onClick="Fn(this)">
<input type=button name="B4" value=4 onClick="Fn(this)">
<input type=button name="B5" value=5 onClick="Fn(this)">
<input type=button name="B6" value=6 onClick="Fn(this)">
<input type=button name="B7" value=7 onClick="Fn(this)">
<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.
Jun 27 '08 #5
On Wed, 16 Apr 2008 23:34:10 +0100, Dr J R Stockton
<jr*@merlyn.demon.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.play('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=background-color:#00ffff name="B0" value=0
onClick="Fn(this)">
<input type=button name="B1" value=1 onClick="Fn(this)">
<input type=button name="B2" value=2 onClick="Fn(this)"><br>

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

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

<input type=button style=background-color:#00ffff name="B9" value=9
onClick="Fn(this)">
<input type=button name="B10" value=10 onClick="Fn(this)">
<input type=button name="B11" value=11 onClick="Fn(this)">
<br>
State, Result : <input type=text name=S>
</form>
Jun 27 '08 #6
On Fri, 18 Apr 2008 08:32:49 +0100, Geoff Cox <gc**@freeuk.notcom>
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=background-color:#00ffff type=button name="B0" value=0
onClick="Fn(this)">
<input type=button name="B1" value=1 onClick="Fn(this)">
<input type=button name="B2" value=2 onClick="Fn(this)"><br>
<input style=background-color:#00ffff type=button name="B3" value=3
onClick="Fn(this)">
<input type=button name="B4" value=4 onClick="Fn(this)">
<input type=button name="B5" value=5 onClick="Fn(this)"><br>
<input style=background-color:#00ffff type=button name="B6" value=6
onClick="Fn(this)">
<input type=button name="B7" value=7 onClick="Fn(this)">
<input type=button name="B8" value=8 onClick="Fn(this)"><br>
<input style=background-color:#00ffff type=button name="B9" value=9
onClick="Fn(this)">
<input type=button name="B10" value=10 onClick="Fn(this)">
<input type=button name="B11" value=11 onClick="Fn(this)">
<br>
State, Result : <input type=text name=S>
</form>
Jun 27 '08 #7
On Wed, 16 Apr 2008 23:34:10 +0100, Dr J R Stockton
<jr*@merlyn.demon.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

Jun 27 '08 #8
On Wed, 16 Apr 2008 23:34:10 +0100, Dr J R Stockton
<jr*@merlyn.demon.co.ukwrote:
Jon,

Even more success!

I can now run some functions

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

function A(f) {soundManager.play('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";alert(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
Jun 27 '08 #9
On Wed, 16 Apr 2008 23:34:10 +0100, Dr J R Stockton
<jr*@merlyn.demon.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.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++; }
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 disableAllExceptFirst() {

}

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

</script>
</head>

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

</form>

<input type = "button" value = "get results" onClick="getResults();">
<div></div>
Jun 27 '08 #10
In comp.lang.javascript message <58mg0413v7n7n3mpju7pbopqfheg597t4k@4ax.
com>, Fri, 18 Apr 2008 09:18:15, Geoff Cox <gc**@freeuk.notcomposted:
>
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.demon.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)
Jun 27 '08 #11
In comp.lang.javascript message <o2bh04l112eko0q8rmliu05q6ciruphomd@4ax.
com>, Fri, 18 Apr 2008 15:21:21, Geoff Cox <gc**@freeuk.notcomposted:
>On Wed, 16 Apr 2008 23:34:10 +0100, Dr J R Stockton
<jr*@merlyn.demon.co.ukwrote:
Jon,

Even more success!

I can now run some functions

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

function A(f) {soundManager.play('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";alert(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.
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.demon.co.uk/TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htmclpdmFAQ;
<URL:http://www.borland.com/newsgroups/guide.htmlnews:borland.* Guidelines
Jun 27 '08 #12
On Fri, 18 Apr 2008 19:33:51 +0100, Dr J R Stockton
<jr*@merlyn.demon.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.length;++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
Jun 27 '08 #13
On Fri, 18 Apr 2008 19:33:51 +0100, Dr J R Stockton
<jr*@merlyn.demon.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.length;++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
Jun 27 '08 #14
In comp.lang.javascript message <qt2i04lm2rq2tvfqoqo9aespbs4115ep4o@4ax.
com>, Fri, 18 Apr 2008 22:02:44, Geoff Cox <gc**@freeuk.notcomposted:
>On Wed, 16 Apr 2008 23:34:10 +0100, Dr J R Stockton
<jr*@merlyn.demon.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.demon.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.
Jun 27 '08 #15
On Sat, 19 Apr 2008 14:35:51 +0100, Dr J R Stockton
<jr*@merlyn.demon.co.ukwrote:
>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.
John,

Not sure whether you have seen my recent post but just one last point!

Re the conflict with prototype.js - the problem I am told is probably
the use of for/in to iterate over the Next values. It certainly seems
to be so as when I try using the "vanilla" type of iteration I can add
the link to prototype.js and do not get the associated error message.

But! I have tried

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

This is not correct and comes up with "Next has no properties" on
answering the 4th question.

What would be the correct "vanilla" type iteration to replace your
following code?

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

Cheers

Geoff
Jun 27 '08 #16
On Sat, 19 Apr 2008 14:35:51 +0100, Dr J R Stockton
<jr*@merlyn.demon.co.ukwrote:

My great sainted ..........

I should have written

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

This is not correct and comes up with "Next has no properties" on
answering the 4th question.

What would be the correct "vanilla" type iteration to replace your
following code?

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

Cheers

Geoff
Jun 27 '08 #17
On Sat, 19 Apr 2008 14:35:51 +0100, Dr J R Stockton
<jr*@merlyn.demon.co.ukwrote:

John

the code below avoids the error "Next has no properties" by adding an
extra item to Arry. But what I need is a way to stop the cycle rather
than start it all over again...cannot yet see how to do this?

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],
/* State 10 : */ [0]] // extra item added
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++;
}

function D(f) {
alert('finished');
}

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.name.substring(1,3);
for (J=0 ; J<12 ; J++) F["B"+J].disabled = true; // clear all
Next = Arry[State];

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

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

}

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

</script>
Jun 27 '08 #18
On Sat, 19 Apr 2008 14:35:51 +0100, Dr J R Stockton
<jr*@merlyn.demon.co.ukwrote:

John,

You will be pleased to hear that all is well at last!

I have used the vanilla iteration and prototype.js is OK. My solution
is not very elegant I expect but it works ...

Many thanks for your 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],
/* State 10 : */ [12],
/* State 11 : */ [12] ]

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++;
}

function D(f) {
alert('finished');
}

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.name.substring(1,3);
for (J=0 ; J<12 ; J++) F["B"+J].disabled = true; // clear all
Next = Arry[State];

for (var J = 0; J < Next.length; ++J) {
F["B"+Next[J]].disabled = false;
}
if ( (State == 10) || (State == 11) ) {
DoSpecificTask[State](F);
sendGroup1Lab5();
} else {
//alert(State);
DoSpecificTask[State](F);
}

}
Jun 27 '08 #19
In comp.lang.javascript message <bmnk04t860fbm2aedho60e43qrnfco2ic7@4ax.
com>, Sat, 19 Apr 2008 22:09:45, Geoff Cox <gc**@freeuk.notcomposted:
>On Sat, 19 Apr 2008 14:35:51 +0100, Dr J R Stockton
<jr*@merlyn.demon.co.ukwrote:

My great sainted ..........

I should have written

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

This is not correct and comes up with "Next has no properties" on
answering the 4th question.

What would be the correct "vanilla" type iteration to replace your
following code?

for (J in Next) F["B"+Next[J]].disabled = false
DoSpecificTask[State](F)
You said, I think, that you have no such problem until you use
prototype.js; therefore, you should ask someone who knows that
prototype.js.

A Wikipedia search for prototype.js offers an amusing diversity of
articles.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.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)
Jun 27 '08 #20
On Sun, 20 Apr 2008 18:10:34 +0100, Dr J R Stockton
<jr*@merlyn.demon.co.ukwrote:
>In comp.lang.javascript message <bmnk04t860fbm2aedho60e43qrnfco2ic7@4ax.
com>, Sat, 19 Apr 2008 22:09:45, Geoff Cox <gc**@freeuk.notcomposted:
>>On Sat, 19 Apr 2008 14:35:51 +0100, Dr J R Stockton
<jr*@merlyn.demon.co.ukwrote:

My great sainted ..........

I should have written

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

This is not correct and comes up with "Next has no properties" on
answering the 4th question.

What would be the correct "vanilla" type iteration to replace your
following code?

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

You said, I think, that you have no such problem until you use
prototype.js; therefore, you should ask someone who knows that
prototype.js.

A Wikipedia search for prototype.js offers an amusing diversity of
articles.
John,

You haven't seen my previous posting yet as all is now well!

The problem re prototype was solved by replacing the for/in by the
ordinary iteration.

In fact someone on the Yahoo Ruby on Rails/Prototype/Scriptaculous
group pointed out that the for/in caused the conflict.

Cheers

Geoff
Jun 27 '08 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Vaishali | last post by:
What is the command for disabling session in ASP.NET
60
by: Fotios | last post by:
Hi guys, I have put together a flexible client-side user agent detector (written in js). I thought that some of you may find it useful. Code is here: http://fotios.cc/software/ua_detect.htm ...
4
by: Steve | last post by:
I have the MDI MFC application ported to .NET. Now this application include mixed managed/unmanaged code. The application displays progress dialog with the cancel button during lenghtly...
3
by: PB | last post by:
What is the rationalle for disabling JavaScript. AFAIK, the primary reason is for "security purposes" - but what specific kind of threats does the protect against? AND - is the disabling of...
1
by: Matt Van Mater | last post by:
I'm looking to get a little more performance out of my database, and saw in the docs a section about disabling autocommit by using the BEGIN and COMMIT keywords. My problem is this: I enforce...
12
by: Nalaka | last post by:
Hi, I suddenly started getting a lot of errors from html validation (some CSS) so I followed the following instructions to disable it. If you'd rather not have these types of HTML validation...
7
by: Varangian | last post by:
Hello I want to disable all the elements which are the childs of a Div element. I tried disabling the div element but it doesn't work... i.e. the child elements were not disabled what shal...
15
by: bruno.desthuilliers | last post by:
On 27 juin, 18:09, "John Salerno" <johnj...@NOSPAMgmail.comwrote: For which definitions of "content" and "logic" ??? The point of mvc is to keep domain logic separated from presentation logic,...
4
by: Umenzi | last post by:
I'm looking for different methods of disabling all internet access that work on XP and Vista. It would need to be reversible. Preferably, these methods would be accessible through a python program...
5
by: jehugaleahsa | last post by:
Hello: I am sure this question comes up a lot. I need to disable the controls on my Windows forms so that when the BindingSource is empty some the controls bound to it will be disabled. This...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.