Forum Moderators: open

Message Too Old, No Replies

JavaScript Arrays

Finding a Link Index #

         

AndreL

5:52 pm on Dec 10, 2003 (gmt 0)

10+ Year Member



I have a Access Table with 1000 Links (<A HREF...). The Table is rendered using ASP. All Links are the same. The Table consists of 10 Fields by 100 Rows.

With a "onClick" event, I want the Script to be able to read the Index Number. The Index Number is then compared to a Random Number Generator from 0 to 999, (1 to 1000?). "If" statements control what happens next.

I need to be advised which direction to take to acheive the required results. Any help would greatly be appreciated.

Thank You,

AndreL

httpwebwitch

7:10 pm on Dec 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd like to help you... but I have no idea what you're trying to do. Do you just want to display a random link chosen out of a list of 1000 that are in your database?

Or are you displaying 1000 items on the screen, and want a random onClick action on each one?

If all links are the same, why are they stored 1000 times?

What are you using the Index Number for?

Are the "if statements" in your javascript, or in the ASP?

Why are you creating an object then comparing it to something random, when you could just choose a random object?

You need to start over and ask your question again. Explain what you're doing, and be clear with words like "table" (HTML table, or database table?), and "script" (javascript, or ASP script?).

AndreL

6:33 am on Dec 11, 2003 (gmt 0)

10+ Year Member



OK, let me start over. The Table has 1000 Links and is 100 by 10. The Table is displayed using an ASP page created with Front Page. Each link refers to the same Javascript with an onClick event. A visitor to the page clicks on a square, there are 1000 squares, and finds out if his or her choice is correct or not. The "IF" statements are in the JavaScript, which points to different actions depending on the outcome
What determines if the choice is a winner or not is by matching the Link Index number with a randomly generated number between 0 and 999 or 1 and 1000. The random number is generated after the Link Index number (square) is chosen.
The Table is designed like a "Punchboard" and was created using MSAccess.

Thank you HTTPWEBWITCH for your inquiry, I hope that this clarifies things a bit.

Purple Martin

8:43 am on Dec 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Firstly, ditch Front Page ;)

You've already got ASP code that writes the link with an onClick event that calls a JavaScript function. You need one extra ASP variable. Set that variable to 1 when you declare it. Where you write the link, put the value of the variable inside the brackets for the function in the onClick event, then increment (increase by one) the value of the ASP variable before you write the next link.

e.g.

the first link looks something like this:
<a href="#" onClick="myFunction(1)">blah</a>

the second link looks something like this:
<a href="#" onClick="myFunction(2)">blah</a>

the third link looks something like this:
<a href="#" onClick="myFunction(3)">blah</a>

and so on.

Now, make your function accept an argument (the number passed by the link) like this:

function myFunction(cell) {
alert("The user clicked on cell number " + cell)
}

You now have a JavaScript variable called "cell" in your function that contains the value of the cell number they clicked on. Compare this to your random number and... you know the rest.

AndreL

5:14 am on Dec 12, 2003 (gmt 0)

10+ Year Member



Thanks Purple Martin, just tried it and works great. Have'nt done the Random yet, but that should'nt be a
problem.

Much Appreciated,

AndreL

httpwebwitch

7:14 pm on Dec 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



well PurpleMartin, you beat me to it. Good answer.