The Syndk8 - Black Hat SEO Paradise
Fantomaster - Industrial Strength Black Hat SEO Tools
Affiliate Earners: Affiliate Programs
Home
Help
Search
Login
Register
RSS for SEOIdiot
Welcome,
Guest
. Please
login
or
register
.
January 09, 2009, 05:58:58 AM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home (Index)
Level 2 Cache: Speciality Items
JavaScript Discussion & Help
javascript error?
Pages: [
1
]
« previous
next »
Print
Author
Topic: javascript error? (Read 437 times)
jammaster82
Expert
Offline
Posts: 300
bloody hacker
javascript error?
«
on:
January 31, 2008, 02:38:05 PM »
Code:
<html>
<script type="text/javascript" language="javascript">
function RollDice()
{
var randomnumber = Math.floor(Math.random()*6)+1; /* generates a random number from 0 to 5, if you want to get a number between 0 and 100 just change the 6 to 1001 */
document.write(randomnumber);
return true;
}
</script>
<input type="button" value="Roll A Die" onclick="RollDice()" >
</html>
it gives me the random number but then says 'loading..'
if i do an alert() instead of document.write it returns okay...
How would i add lines to the document inside that function
and return, not that i need to do it or anything but always love
to learn.. why does it hang on the document.write?
«
Last Edit: January 31, 2008, 03:24:44 PM by jammaster82
»
Logged
Of course Big Brother exists, he is the embodiment of the party..... Does he exist in the same way I exist?....... You, do not exist.
DangerMouse
Expert
Offline
Posts: 177
Re: javascript error?
«
Reply #1 on:
January 31, 2008, 04:00:31 PM »
I know nowt about javascipt, but I'd imagine its something to do with scope? Variables are normally private to a function, in this instance write is being called on a 'document' object, but that 'document' object is not visible.
I could be totally barking up the wrong tree here, its just a guess.
DM
Logged
manu`
Rookie
Offline
Posts: 10
Re: javascript error?
«
Reply #2 on:
January 31, 2008, 04:21:00 PM »
Code:
<html>
<script type="text/javascript" language="javascript">
function RollDice()
{
var randomnumber = Math.floor(Math.random()*7);
if(randomnumber == 0)
{
randomnumer++;
}
document.forms[0].dice.value = randomnumber;
}
</script>
<form name="yourname" method="get">
<input type="button" value="Roll A Die" onclick="RollDice()" >
<input type="text" name="dice" value="" readonly>
</form>
</html>
this should work.
Logged
jammaster82
Expert
Offline
Posts: 300
bloody hacker
Re: javascript error?
«
Reply #3 on:
January 31, 2008, 07:56:17 PM »
AH,... thank you both...
Code:
function RollDice()
{
var randomnumber = Math.floor(Math.random()*7);
if(randomnumber == 0)
{
randomnumber++;
}
document.forms[0].dice.value = randomnumber;
}
does this not produce 7 different random numbers
at first until modified,returning a 1 for both 0 and 1?
in the above quoted code arent there
eight possible random numbers at first?
--> 0,1,2,3,4,5,6 and 7 ?
«
Last Edit: January 31, 2008, 09:42:17 PM by jammaster82
»
Logged
Of course Big Brother exists, he is the embodiment of the party..... Does he exist in the same way I exist?....... You, do not exist.
manu`
Rookie
Offline
Posts: 10
Re: javascript error?
«
Reply #4 on:
February 01, 2008, 03:30:09 AM »
change randomnumber++ to randomnumber = Math.floor(Math.random()*7);
now it generates a new random number from 1 to 6
Logged
jammaster82
Expert
Offline
Posts: 300
bloody hacker
Re: javascript error?
«
Reply #5 on:
February 01, 2008, 05:46:12 AM »
what if its zero again?>
«
Last Edit: February 01, 2008, 05:56:21 AM by jammaster82
»
Logged
Of course Big Brother exists, he is the embodiment of the party..... Does he exist in the same way I exist?....... You, do not exist.
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Level 1 Cache: General Discussion
-----------------------------
=> Init() - New Member Introductions
=> Callback Routines
=> freemem() & garbage collection
=> All Things General Tech
=> All Things Apple
=> All Things Database
=> All Things *nix
=> All Things Windows
-----------------------------
Level 2 Cache: Speciality Items
-----------------------------
=> AJAX, Specifically: Techniques, Code & Examples
=> ASP & .NET
=> C/++/#, Java, Delphi and other heavies
=> ColdFusion
=> JavaScript Discussion & Help
=> Javascript Code Repository & Examples
=> Music Technology
=> PERL
=> PHP Discussions / Help
=> PHP Code Repository / Examples
=> Python/Lisp/Scheme/Erlang/Obscurities
=> Regex Discussion & Examples
=> SMF Discussion
-----------------------------
phpMyIDE
-----------------------------
=> Announcements & Updates
=> Support Threads
Perkiset's Place Home
Best of The Cache
phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's
Pinkhat's Perspective
cache
mart
coder
programmers
ajax
php
javascript
Loading...