WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You

WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You


You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1Help to view a random code Empty Help to view a random code Sun Mar 28, 2010 6:34 pm

Unknown Data

Unknown Data
Registered Member
Registered Member
Hey everybody!

Note; I don't know where I should put this thread, because there was no category to Javasripts, so I just placed it in HTML, because I would say that is closest to.

I'm going to make a cool project working on my website, but I can't make the last part work.
Can somebody please tell me how I can view a random code on a page, so it's not the same everytime a user/guest se it? I got these two codes i would like to switch between.

1. Code:
Code:
<center><br/><a onclick="window.open(this.href,'DigiviceJagt','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width=300,height=200,left=500,top=250,status'); return false" href="http://digimon-world.danskforum.net/Digivice-Jagt-FS-h51.htm"><input class="liteoption" type="button" name="" onclick="document.searchform.google.value='';" value="Digivice Jagt" /></a><br/></center>

2. Code:
Code:
<center><br/><a onclick="window.open(this.href,'DigiviceJagt','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width=300,height=200,left=500,top=250,status'); return false" href="http://digimon-world.danskforum.net/Digivice-RS-h54.htm"><input class="liteoption" type="button" name="" onclick="document.searchform.google.value='';" value="Digivice Jagt" /></a><br/></center>

~Unknown Data



Last edited by Unknown Data on Sat Apr 03, 2010 11:44 pm; edited 1 time in total

http://woops.dk

2Help to view a random code Empty Re: Help to view a random code Mon Mar 29, 2010 12:22 pm

ankillien

ankillien
Administrator
Administrator
Hi!

I wrote a code that will display a random code of two different codes...

Code:
<script language="JavaScript">
<!--

function randomCode(){

  var myCodes=new Array()
  myCodes[1]="<div

style='background:red;height:50px;width:50px;'>&nbsp</div>"
  myCodes[2]="<div

style='background:green;height:50px;width:50px;'>&nbsp</div>"

  var ry=Math.floor(Math.random()*3)

  if (ry==0)
    ry=1
    document.write(myCodes[ry])
}

  randomCode()
//-->
</script>

Please try this code on a HTML page and see if this is what you want.
This code will generate a box either green or red randomly.

3Help to view a random code Empty Re: Help to view a random code Mon Mar 29, 2010 3:41 pm

Unknown Data

Unknown Data
Registered Member
Registered Member
Thank you very much! (:

But I'm not sure it working, because each time I try it shows the first code, I can't get it to show the second code. And then I tryed later, and now it won't show one of the codes.

http://woops.dk

4Help to view a random code Empty Re: Help to view a random code Mon Mar 29, 2010 4:42 pm

ankillien

ankillien
Administrator
Administrator
It is a randomizer. So it will display either of the codes randomly.
If you keep refreshing the page, it will display both at any time.

Since there are only 2 options it may repeat same code multiple times but it will surely show other code too.

5Help to view a random code Empty Re: Help to view a random code Tue Mar 30, 2010 3:57 pm

Unknown Data

Unknown Data
Registered Member
Registered Member
All right, but I can't get it to show the code - when I post the code on my page, it won't show anything.

And just to be sure, isn't this the way it has to look (I've put the to codes in the script).

Code:
<script language="JavaScript">
<!--

function randomCode(){

  var myCodes=new Array()
  myCodes[1]="<center><br/><a onclick="window.open(this.href,'DigiviceJagt','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width=300,height=200,left=500,top=250,status'); return false" href="http://digimon-world.danskforum.net/Digivice-Jagt-FS-h51.htm"><input class="liteoption" type="button" name="" onclick="document.searchform.google.value='';" value="Digivice Jagt" /></a><br/></center><div

style='background:red;height:50px;width:50px;'>&nbsp</div>"
  myCodes[2]="<center><br/><a onclick="window.open(this.href,'DigiviceJagt','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width=300,height=200,left=500,top=250,status'); return false" href="http://digimon-world.danskforum.net/Digivice-RS-h54.htm"><input class="liteoption" type="button" name="" onclick="document.searchform.google.value='';" value="Digivice Jagt" /></a><br/></center><div

style='background:green;height:50px;width:50px;'>&nbsp</div>"

  var ry=Math.floor(Math.random()*3)

  if (ry==0)
    ry=1
    document.write(myCodes[ry])
}

  randomCode()
//-->
</script>

http://woops.dk

6Help to view a random code Empty Re: Help to view a random code Sat Apr 03, 2010 5:03 pm

Unknown Data

Unknown Data
Registered Member
Registered Member
Bump, I really need help.

http://woops.dk

7Help to view a random code Empty Re: Help to view a random code Sat Apr 03, 2010 10:38 pm

ankillien

ankillien
Administrator
Administrator
Sorry, I just forgot about this topic.

Here is the perfect code for you...

Code:
<script language="JavaScript">

function randomCode(){

  var myCodes=new Array()
 
  myCodes[1]="<center><br/><a onclick=\"window.open(this.href,\'DigiviceJagt\',\'resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width=300,height=200,left=500,top=250,status\'); return false\" href=\"http://digimon-world.danskforum.net/Digivice-Jagt-FS-h51.htm\"><input class=\"liteoption\" type=\"button\" onclick=\"document.searchform.google.value=\'\';\" value=\"Digivice Jagt 1\" /></a><br/></center>"

  myCodes[2]="<center><br/><a onclick=\"window.open(this.href,\'DigiviceJagt\',\'resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width=300,height=200,left=500,top=250,status\'); return false\" href=\"http://digimon-world.danskforum.net/Digivice-RS-h54.htm\"><input class=\"liteoption\" type=\"button\" onclick=\"document.searchform.google.value=\'\';\" value=\"Digivice Jagt 2\" /></a><br/></center>"

  var ry=Math.floor(Math.random()*3)

  if (ry==0)
    ry=1
    document.write(myCodes[ry])
}

  randomCode()

</script>

There was a bug with quote signs in the code. Now it should work fine Very Happy

8Help to view a random code Empty Re: Help to view a random code Sat Apr 03, 2010 11:44 pm

Unknown Data

Unknown Data
Registered Member
Registered Member
THANK you very much! It helped, and just in the right time. (:

Problem = Solved

http://woops.dk

9Help to view a random code Empty Re: Help to view a random code Sun Apr 04, 2010 12:57 am

Sanket

Sanket
Administrator
Administrator
Solved | Locked

http://www.webartzforum.com

Sponsored content


View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum