Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-09-2004, 03:14 PM   PM User | #1
davegreen
New to the CF scene

 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
davegreen is an unknown quantity at this point
Merging codes

Hi,

i was wondering if anyone could help me.

i have two bits of code

<html>
<body>
<script type="text/javascript">


number1 = parseInt(Math.random() * 6+1);
number2 = parseInt(Math.random() * 6+1);
number3 = parseInt(Math.random() * 6+1);
number4 = parseInt(Math.random() * 6+1);

document.write(number1 + "" + number2 + "" + number3 + "" + number4);


document.write('<img src="die'+ number1 +'.bmp">');
document.write(" ");
document.write('<img src="die'+ number2 +'.bmp">');
document.write(" ");
document.write('<img src="die'+ number3 +'.bmp">');
document.write(" ");
document.write('<img src="die'+ number4 +'.bmp">');

</script>
</body>
</html>

This displays 4 random die images i have saved in file
davegreen is offline   Reply With Quote
Old 12-09-2004, 03:15 PM   PM User | #2
davegreen
New to the CF scene

 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
davegreen is an unknown quantity at this point
an this is the 2nd one


<html>

<body>
<script type="text/javascript">

function nextroll(){
number1 = parseInt(Math.random() * 6+1);
number2 = parseInt(Math.random() * 6+1);
number3 = parseInt(Math.random() * 6+1);
number4 = parseInt(Math.random() * 6+1);

document.Score.display.value+=(number1 + "" + number2 + "" + number3 + "" + number4)+"\n";

}

document.write('<img src="die'+ number1 +'.bmp">');
document.write(" ");
document.write('<img src="die'+ number2 +'.bmp">');
document.write(" ");
document.write('<img src="die'+ number3 +'.bmp">');
document.write(" ");
document.write('<img src="die'+ number4 +'.bmp">');

</script>

<form name="Score">
<center>
<input type="button" value="roll" onclick=nextroll()>
<input type="reset" value="reset">
<textarea name="display" rows="20" cols="40" readonly></textarea>

</form>

</body>

</html>
davegreen is offline   Reply With Quote
Old 12-09-2004, 03:16 PM   PM User | #3
davegreen
New to the CF scene

 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
davegreen is an unknown quantity at this point
as you can see in the 2nd one i want a button that on roll displays everything, and puts it into a text box

it does that, but doesnt even display the image

ive even tried making the function cover that action too
davegreen is offline   Reply With Quote
Old 12-09-2004, 04:29 PM   PM User | #4
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
Your problem is two fold...

Your images are never loading because the variables (number1, number2, ect...) although global are not defined on page load (they are defined when nextroll is called) when the document.write statements write your image tags to the page... Thus, the very first image looking for the variable number1 throws and error and the script quits right there (turn on error reporting so you can find these yourself)...

And, even if the images loaded, there is nothing in your nextroll function to update the image sources... so naturaly the textarea is updated but the images will not be updated even if they were visible on the page....

Suggestion: Place the images in the body of the document using names or ids along with default image sources and place your next roll in the head and change the image and either call the function window.onload or body onload changing the image sources whenever the function fires...

Is this homework? Seems so...

.....Willy
Willy Duitt is offline   Reply With Quote
Old 12-09-2004, 04:34 PM   PM User | #5
jbot
Senior Coder

 
Join Date: Feb 2004
Location: Edinburgh
Posts: 1,352
Thanks: 0
Thanked 0 Times in 0 Posts
jbot is an unknown quantity at this point
Quote:
Originally Posted by Willy Duitt
Is this homework? Seems so.
could be.
see here for details
__________________
*keep it simple (TM)
jbot is offline   Reply With Quote
Old 12-09-2004, 05:15 PM   PM User | #6
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
Quote:
Originally Posted by jbot
Hmmmmm;

Multiple online personalities...
I suppose I should add both: jonnyheald & davegreen
To my do not write code for list....

Cheers and thanks for the heads up;
.....Willy
Willy Duitt is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:07 AM.


Advertisement
Log in to turn off these ads.