Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

October 04, 2022, 11:16:15 PM

Login with username, password and session length
Members
  • Total Members: 3848
  • Latest: rrolle
Stats
  • Total Posts: 193513
  • Total Topics: 21092
  • Online today: 72
  • Online ever: 3540
  • (September 02, 2022, 06:38:54 PM)
Users Online
Users: 0
Guests: 45
Total: 45

Author Topic: Help making Javascript function work correctly Die roller block  (Read 11897 times)

0 Members and 1 Guest are viewing this topic.

pjr

  • Guest
Below is a bit of simple code that doesnt work. How do I get the button push to make the call and return the value? Also for some reason there is a lot of blank space above the table when I create it. Can one of you more experianced TP useres help me out here?

Code: [Select]
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var die = 6;
var dice = 3;
function dice_roll(die, dice) {
var roll = 0;
for (loop=0; loop < dice; loop++) {
roll = roll + Math.round(Math.random() * die) % die + 1;
}
document.roller.drtext.value = roll;
}
// End -->
</script>


<form name=roller>
<table border=2 cellpadding=2>
<tr>
<td colspan=1 align=middle>Type?</td>
<td colspan=1 align=middle>Number?</td>
</tr>
<tr>
<td valign=top align=middle>
<p><input type=radio name=sides onclick="die = 2">2
<p><input type=radio name=sides onclick="die = 4">4
<p><input type=radio checked name=sides onclick="die = 6">6
<p><input type=radio name=sides onclick="die = 8">8
<p><input type=radio name=sides onclick="die = 10">10
<p><input type=radio name=sides onclick="die = 12">12
<p><input type=radio name=sides onclick="die = 20">20
<p><input type=radio name=sides onclick="die = 100">100
</td>
<td valign=top align=middle>
<p><input type=radio name=number onclick="dice = 1">1
<p><input type=radio name=number onclick="dice = 2">2
<p><input type=radio checked name=number onclick="dice = 3">3
<p><input type=radio name=number onclick="dice = 4">4
<p><input type=radio name=number onclick="dice = 5">5
<p><input type=radio name=number onclick="dice = 6">6
<p><input type=radio name=number onclick="dice = 8">8
<p><input type=radio name=number onclick="dice = 10">10
</td>
</tr>
<tr>
<td align=middle colspan=2>
<input type=button value="Roll Dice" name=button onclick="dice_roll(die, dice)">
<input type=text size=10 name=drtext>
</td>
</tr>
</table>
</form>

gerrymo

  • Guest
Re: Help making Javascript function work correctly Die roller block
« Reply #1 on: March 15, 2006, 07:50:21 AM »
Works fine for me. See the screenshot below. What I think you've done, is not change the block type from html to javascript/html. This will leave a space at the top.

[attachment deleted by admin]

pjr

  • Guest
Re: Help making Javascript function work correctly Die roller block
« Reply #2 on: March 15, 2006, 08:01:09 AM »
You're correct I actually discovered that shortly after I posted. I thought I had deleted this post too. oh well! :)

 Thanks however!

gerrymo

  • Guest
Re: Help making Javascript function work correctly Die roller block
« Reply #3 on: March 15, 2006, 08:03:26 AM »
The question and solution should help someone else.

Mitch

  • Guest
Re: Help making Javascript function work correctly Die roller block
« Reply #4 on: March 15, 2006, 08:17:32 AM »
It works fine for me too.

Thanks for the code by the way. I made some small changes but it will fit in well with my RP site.

crip

  • Guest
Re: Help making Javascript function work correctly Die roller block
« Reply #5 on: March 15, 2006, 08:30:50 AM »
Is this a game of sort?  ???

pjr

  • Guest
Re: Help making Javascript function work correctly Die roller block
« Reply #6 on: March 15, 2006, 08:38:38 AM »
well I am running a play by post rpg site here www.ourplacetoplay.com/forum so yes and no crip. Mitch what changes did you make always like to tinker myself...:)

crip

  • Guest
Re: Help making Javascript function work correctly Die roller block
« Reply #7 on: March 15, 2006, 08:55:52 AM »
Is that (Fire-Fly) a TV series on Si-Fi channel?
......If it is, I love that show, I've not missed one episode yet..
...I'm also a huge SG-1 fan too.. :)

pjr

  • Guest
Re: Help making Javascript function work correctly Die roller block
« Reply #8 on: March 15, 2006, 09:14:02 AM »
Yes it is. It originally aired on Fox they canceled it and there was a movie called Serenity all available on DVD now

Mitch

  • Guest
Re: Help making Javascript function work correctly Die roller block
« Reply #9 on: March 15, 2006, 09:25:47 AM »
well I am running a play by post rpg site here www.ourplacetoplay.com/forum so yes and no crip. Mitch what changes did you make always like to tinker myself...:)

http://www.games-n-things.net

you can check it out here but be nice I am in midst of changing the site soo its a mess.
Not alot of things I just changed the looks of it a bit.

I heard I should watch fire fly

and serenity was a damn good movie.