| | |
Random Topic JS
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Is there a better way to write this short code? It goes to topics that dont exist, I want it to check first so that dosent happen, and not to go to topics in a particular forum, a forum url looks like this (last number being the forum id)
http://inny.ipbfree.com/index.php?showforum=1
any ideas?
http://inny.ipbfree.com/index.php?showforum=1
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<center><script> //rough estimate of topics on your forum topiccount = 2000 topicnum = Math.floor(Math.random()*topiccount) document.write("<a href='http://inny.ipbfree.com/index.php?showtopic=" + topicnum + "'><img src=http://www.parexcellence.co.uk/weblink/images/randomlink.gif border=0></a>") </script> </center>
any ideas?
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
W. C. Fields
Try to change the random generation to an expression like:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
topicnum = Math.round(Math.random()*(topiccount-1))+0;
You keep going, have a Nice day!
Henry.
Before printing this message, make sure is necessary.
Henry.
Before printing this message, make sure is necessary.
Are you sure that you have 2000 topics? Or is that only the maximum number?
You would need to know the maximum number of topics for the random generation number to work between the range. So, in the expression:
"topiccount" must be the maximum o available topics.
You would need to know the maximum number of topics for the random generation number to work between the range. So, in the expression:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
topicnum = Math.round(Math.random()*(topiccount-1))+0;
"topiccount" must be the maximum o available topics.
You keep going, have a Nice day!
Henry.
Before printing this message, make sure is necessary.
Henry.
Before printing this message, make sure is necessary.
I have just uinder 2000 topics but that changes everyday. It may go to something like topic number 1876 which may have been deleted or may not exist yet. This will trigger my error page. Id rather that didnt happen because it gives the impression that something is broken
Last edited by Inny; Apr 20th, 2008 at 8:36 am.
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
W. C. Fields
So if I understand correctly, there is not a problem with the random generation but with the links; those, you have to include some kind of check before you write the link on your page, something like
...
get the number
check for existence
go back to check if does not exists
write the link
...
do you hold a record of existing/active topics?
...
get the number
check for existence
go back to check if does not exists
write the link
...
do you hold a record of existing/active topics?
You keep going, have a Nice day!
Henry.
Before printing this message, make sure is necessary.
Henry.
Before printing this message, make sure is necessary.
I have Logs of Existing Topics yes..
the javascript for it (search stats) seems to be (url removed for security reasons)
the javascript for it (search stats) seems to be (url removed for security reasons)
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script type='text/javascript'> function dojump() { if ( document.jumpmenu.val.options[document.jumpmenu.val.selectedIndex].value != '' ) { window.location.href = 'url removed'+ '&' + document.jumpmenu.val.options[document.jumpmenu.val.selectedIndex].value; } } </script>
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
W. C. Fields
if "selectedIndex" within your function is the topic than can exist or not, I would create a function to find out the correct random destination, something like:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function destination() { var urltogo = ''; while (urltogo == '') { selectedIndex = Math.round(Math.random()*(topiccount-1))+0; urltogo = document.jumpmenu.val.options[document.jumpmenu.val.selectedIndex].value; } return urltogo; }
You keep going, have a Nice day!
Henry.
Before printing this message, make sure is necessary.
Henry.
Before printing this message, make sure is necessary.
Thanks So much For your Help On this. Think I have it now. 
While your online mate, Do you think you could help with this one? (see last post)
http://www.daniweb.com/forums/thread113427.html
Much Appreciated!

While your online mate, Do you think you could help with this one? (see last post)
http://www.daniweb.com/forums/thread113427.html
Much Appreciated!
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
W. C. Fields
![]() |
Similar Threads
- Hidden program installs .dlls with randomly generated names in random "notify" reg. (Viruses, Spyware and other Nasties)
- VB 6.0. Creating a file for random access (Visual Basic 4 / 5 / 6)
- Random Freezing and LAN uninstalling (Windows NT / 2000 / XP)
- The Random Insanity topic! (Geeks' Lounge)
- *Random System Restarts* (Win XP) (Windows NT / 2000 / XP)
- Random Windows XP Freezing - Hardware?!? (Windows NT / 2000 / XP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: if statement not working
- Next Thread: Help required for javascript ?
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxhelp ajaxjspservlets animate array automatically beta box browser captchaformproblem cart child close codes column css date debugger decimal dependent design disablefirebug dom download element embed engine enter error events ext file firefox focus form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe index java javascript javascripthelp2020 jawascriptruntimeerror jquery jsp jump libcurl listbox maps masterpage math media menu microsoft mimic mp4 onmouseoutdivproblem onmouseover onreadystatechange paypal pdf php player position post problem programming prototype redirect safari scale scriptlets scroll search security select software sql toggle unicode variables w3c web website window windowofwords \n





