Advertise Here

Author Topic: Random Selection  (Read 4561 times)

0 Members and 1 Guest are viewing this topic.

Offline trevix

  • SMF For Free Sr. Member
  • *
  • Posts: 302
    • View Profile
    • Canvas

  • Total Badges: 16
    Badges: (View All)
    Topic Starter Combination Level 3 Level 2 Level 1
Random Selection
« on: November 18, 2007, 06:18:42 am »
Simple script, took me a while to work it out just right.  I used it on my sytlesheet generator.


<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
var op_text = new Array ();
op_text[0] = "what ever you want, html is ok 2";
op_text[1] = "some more stuff";
op_text[2] = "guess what...";
op_text[3] = "more stuff";
var i = Math.round(3*Math.random());

document.write(op_text[i]);

//-->
</SCRIPT>


you can delete options and add as many as you want, upon refresh it will display a diff option.
after you got the all the options take the last one (in this case 3) and plug it into "var i = Math.round(3*Math.random());" replace the three with the last option so it know how many there are.

Your first option is always 0

Combine it with mr.css refresh script for fun lol
« Last Edit: November 18, 2007, 08:54:50 pm by trevix »

Ad Machine - Free advertising and tips on how to promote your board.

Offline Crasy

  • Global Moderator
  • *
  • Posts: 3960
  • Semi-Retired ;)
    • View Profile

  • Total Badges: 29
    Badges: (View All)
    Poll Starter Poll Voter Seventh year Anniversary Arcade Highscore Windows User
Re: Random Selection
« Reply #1 on: November 23, 2007, 04:16:20 pm »
You should note to people that putting and " in the script will mess with it.

So something like <img src="imageurl"> will mess with it. Right? I think.
Did my answer help you? Want to help out hosting costs?


Every donation counts.

Offline LaundryLady

  • Helpers
  • *
  • Posts: 3253
  • Internet Challenged
    • View Profile

  • Total Badges: 26
    Badges: (View All)
    Seventh year Anniversary Sixth year Anniversary Search Poll Voter Level 5
Re: Random Selection
« Reply #2 on: November 23, 2007, 04:40:48 pm »
Possibly using ' instead of this " would be ok.  I know it is in Agent Moose's stuff.  Of course I have no idea what this code does.  I am unable to see the concept of it in my head.


And I Play:  Mafia-Mandemz

Offline Coreeeey

  • SMF For Free Sr. Member
  • *
  • Posts: 307
    • View Profile
    • Forum Evolve

  • Total Badges: 16
    Badges: (View All)
    Topic Starter Combination Level 3 Level 2 Level 1
Re: Random Selection
« Reply #3 on: November 23, 2007, 05:24:45 pm »
Possibly using ' instead of this " would be ok.  I know it is in Agent Moose's stuff.  Of course I have no idea what this code does.  I am unable to see the concept of it in my head.

I think, its supposed to show a new text everytime the page is refreshed. So you could visit the site and it would show text 1 and then later you could go back and it would show a different text (2, 3, 4, 0, and so on)

Offline trevix

  • SMF For Free Sr. Member
  • *
  • Posts: 302
    • View Profile
    • Canvas

  • Total Badges: 16
    Badges: (View All)
    Topic Starter Combination Level 3 Level 2 Level 1
Re: Random Selection
« Reply #4 on: November 23, 2007, 06:28:49 pm »
nope its random, and yes you need ' not " in html

Ad Machine - Free advertising and tips on how to promote your board.

 

Related Topics

  Subject / Started by Replies Last post
1 Replies
1989 Views
Last post October 03, 2007, 05:40:13 am
by Agent Moose
0 Replies
3139 Views
Last post March 24, 2008, 01:01:26 pm
by Ravage™
7 Replies
1359 Views
Last post July 06, 2008, 11:21:02 pm
by simply sibyl
5 Replies
1052 Views
Last post January 05, 2009, 06:36:23 am
by Ltgh
1 Replies
771 Views
Last post October 04, 2009, 09:08:16 pm
by Seldom Fail