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

Recent

Welcome to TinyPortal. Please login or sign up.

March 28, 2024, 01:03:35 PM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,104
  • Total Topics: 21,212
  • Online today: 212
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 68
  • Total: 68

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.

crip

#10
on TV, is Serenity the ship.. or the beautiful companion?  :P :P :P
I know who Jewel Satie is, not her but the capanion is Serenity??


pjr

Inara is the companion. The ship is Serenity.

And for the record my favorite woman was Saffron from the Our Mrs Reynolds episode

All your questions can be answered here...http://www.fireflywiki.org/Firefly/HomePage


BZR

anyone know how to add color to this roller
my back ground is black so it wont let me see the numbers

pjr

odd so is mine and I get white text......http://www.ourplacetoplay.com/forum/index.php
put the tags <color=white> </color> arround it should work

BZR


then i have done something wrong :)

1st i took a block made it html/java. then i edited it and added the script