TinyPortal

Development => Block Codes => Topic started by: pjr on March 15, 2006, 07:23:50 AM

Title: Help making Javascript function work correctly Die roller block
Post by: pjr on March 15, 2006, 07:23:50 AM
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>
Title: Re: Help making Javascript function work correctly Die roller block
Post by: gerrymo 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]
Title: Re: Help making Javascript function work correctly Die roller block
Post by: pjr 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!
Title: Re: Help making Javascript function work correctly Die roller block
Post by: gerrymo on March 15, 2006, 08:03:26 AM
The question and solution should help someone else.
Title: Re: Help making Javascript function work correctly Die roller block
Post by: Mitch 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.
Title: Re: Help making Javascript function work correctly Die roller block
Post by: crip on March 15, 2006, 08:30:50 AM
Is this a game of sort?  ???
Title: Re: Help making Javascript function work correctly Die roller block
Post by: pjr 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...:)
Title: Re: Help making Javascript function work correctly Die roller block
Post by: crip 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.. :)
Title: Re: Help making Javascript function work correctly Die roller block
Post by: pjr 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
Title: Re: Help making Javascript function work correctly Die roller block
Post by: Mitch 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.
Title: Re: Help making Javascript function work correctly Die roller block
Post by: crip on March 15, 2006, 09:34:31 AM
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??

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.darkhorizons.com%2Ftv%2Ffirefly-logo.jpg&hash=cc7484499451d0c64879a06d9b8b3947d6143bfa) (http://www.darkhorizons.com/tv/firefly-logo.jpg[/img)
Title: Re: Help making Javascript function work correctly Die roller block
Post by: pjr on March 15, 2006, 09:48:03 AM
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

Title: Re: Help making Javascript function work correctly Die roller block
Post by: BZR on March 15, 2006, 08:06:20 PM
anyone know how to add color to this roller
my back ground is black so it wont let me see the numbers
Title: Re: Help making Javascript function work correctly Die roller block
Post by: pjr on March 15, 2006, 08:09:34 PM
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
Title: Re: Help making Javascript function work correctly Die roller block
Post by: BZR on March 15, 2006, 08:13:11 PM

then i have done something wrong :)

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