TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

April 29, 2024, 09:48:39 PM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,173
  • Total Topics: 21,219
  • Online today: 152
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 86
  • Total: 86

Help making Javascript function work correctly Die roller block

Started by pjr, March 15, 2006, 02:23:50 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pjr

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?

<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

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

You're correct I actually discovered that shortly after I posted. I thought I had deleted this post too. oh well! :)

Thanks however!

gerrymo


Mitch

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.


pjr

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

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

Yes it is. It originally aired on Fox they canceled it and there was a movie called Serenity all available on DVD now

Mitch

Quote from: pjr on March 15, 2006, 03:38:38 PM
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.