agnarkb Posted April 19, 2009 Share Posted April 19, 2009 I´m currently working on a Bingo project. I have written a script, using JS and HTML for the webpage, that generates a bingo card with random numbers. However, I´m now having problems with what I thought would be relatively simple. The bingo number caller or whatever it is called. The idea I had was to use AJAX and it would display random chars and numbers[b1, O67...] that would be the bingo caller in a horizontal line below the card.I have tried everything I know but I just can´t get it to work. Do you have any codes that do this sort of things or similar? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 19, 2009 Share Posted April 19, 2009 Can you show your code? How is it not working? Link to comment Share on other sites More sharing options...
agnarkb Posted April 19, 2009 Author Share Posted April 19, 2009 Can you show your code? How is it not working?Used some of a code to create the bingo card from a book I own.Then I tried writing some code to do the random numbers. I couldn´t do it right with AJAX. The only code that somewhat worked, but not totally what I was looking for.div:<div id='random'></div><br /> <input name="button" type="button" value="Click" onClick="randomBingoCallNumber(75,25)"/> </div> java script: var i=1;function randomBingoCallNumber(maximumValue, numberOfTimes){ i++; document.getElementById('random').innerHTML=''; var Number = Math.Floor((Math.random()*parseInt(maxVal)).toFixed(2)); document.getElementById('random').innerHTML=Number; //gett if(i< = numberOfTimes) setTimeout("randomBingoCallNumber("+maximumValue+","+numberOfTimes+")",500); else i=1;} I want it to use AJAX to make it refresh automatically, not pushing a button. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 19, 2009 Share Posted April 19, 2009 var Number = Math.Floor((Math.random()*parseInt(maxVal)).toFixed(2));That variable is undefined.if(i< = numberOfTimes)It's not valid to have a space there, the operator is "<=". With a space it's 2 different operators. Link to comment Share on other sites More sharing options...
jeffman Posted April 19, 2009 Share Posted April 19, 2009 Are you using AJAX because you have multiple players on multiple browsers? That's going to open up a lot of other issues, too.If you simply want an automated process, look into the Javascript setInterval() functionThat can be used locally, or to call a PHP script at regular intervals via AJAX. Link to comment Share on other sites More sharing options...
jeffman Posted April 19, 2009 Share Posted April 19, 2009 Also, better not use Number for a var name. Number() is a built in function you might want to use some time, but using it as a var overwrites the function. Link to comment Share on other sites More sharing options...
agnarkb Posted April 19, 2009 Author Share Posted April 19, 2009 Are you using AJAX because you have multiple players on multiple browsers? That's going to open up a lot of other issues, too.If you simply want an automated process, look into the Javascript setInterval() functionThat can be used locally, or to call a PHP script at regular intervals via AJAX.I mostly want an automated process. Like it would be in real life. Link to comment Share on other sites More sharing options...
agnarkb Posted April 21, 2009 Author Share Posted April 21, 2009 I still haven´t figured this out, do you guys know of any JS/AJAX code that would do this? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 21, 2009 Share Posted April 21, 2009 With this line in there:document.getElementById('random').innerHTML='';It's going to delete the contents of that div every time it runs the function. So the first time it runs, it will delete the contents, then print a number there. The second time it runs, when i=2, it will again delete the contents and print another number there. So after 25 times you'll end up with 1 number there. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.