LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-18-2006, 05:19 PM   #1
Hosiah
Member
 
Registered: Sep 2004
Location: Des Moines, Iowa
Distribution: Slackware, Mandriva, Debian derivatives, +BSD/ Solaris/ Minix/ plan9/ GNU/HURD...
Posts: 185

Rep: Reputation: 30
my first Javascript doesn't work in Blogger?


I'll throw it out here on the off chance there's a Java wizard handy. So, I finally quit putting off learning Javascript, and I'm starting out with a simple button-click dice-roller. It displays two random die icons whenever the button is clicked. Here's the code, presented in a stand-alone webpage for clarity's sake:


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="content-type">
  <title>Roll the Dice</title>
</head>
<body>
<script language="JavaScript">
<!--
function get_random()
{
var ranNum= Math.round((Math.random()*5)+1);
if(ranNum==1)
{value1.src="http://photos1.blogger.com/blogger/1875/341/1600/dice_one.png";}
if(ranNum==2)
{value1.src="http://photos1.blogger.com/blogger/1875/341/1600/dice_two.png";}
if(ranNum==3)
{value1.src="http://photos1.blogger.com/blogger/1875/341/1600/dice_three.png";}
if(ranNum==4)
{value1.src="http://photos1.blogger.com/blogger/1875/341/1600/dice_four.png";}
if(ranNum==5)
{value1.src="http://photos1.blogger.com/blogger/1875/341/1600/dice_five.png";}
if(ranNum==6)
{value1.src="http://photos1.blogger.com/blogger/1875/341/1600/dice_six.png";}
var ranNum= Math.round((Math.random()*5)+1);
if(ranNum==1)
{value2.src="http://photos1.blogger.com/blogger/1875/341/1600/dice_one.png";}
if(ranNum==2)
{value2.src="http://photos1.blogger.com/blogger/1875/341/1600/dice_two.png";}
if(ranNum==3)
{value2.src="http://photos1.blogger.com/blogger/1875/341/1600/dice_three.png";}
if(ranNum==4)
{value2.src="http://photos1.blogger.com/blogger/1875/341/1600/dice_four.png";}
if(ranNum==5)
{value2.src="http://photos1.blogger.com/blogger/1875/341/1600/dice_five.png";}
if(ranNum==6)
{value2.src="./dice_six.png";}
}
//-->
</script>
<form name="form1"> <img src="http://photos1.blogger.com/blogger/1875/341/1600/dice_three.png" name="value1"
 border="0" height="48" width="48"> <img src="http://photos1.blogger.com/blogger/1875/341/1600/dice_four.png"
 name="value2" border="0" height="48" width="48">
  <p><input value="Roll the dice." onclick="get_random()" type="button"></p>
  <br>
  <br>
</form>
</body>
</html>
Now, I try this from my desktop in Firefox, Mozilla, and Konqueror and it works. I paste the script.../script block inside the head tag and the form.../form block into the body. I check it in Blogger preview and it works. Then I save it and try it in my blog proper, and the dice and button show and I can click it, but it doesn't change the dice. Also tried it all in the body the way I show it here. Still no luck. Any idea why?

Here's the dice icons, by the way, if anybody wants them.

PS Javascript's kinda fun! I'm doing this as a proof-of-concept before I hopefully code some fun little toys to spice up my blog with.
 
Old 01-19-2006, 12:27 AM   #2
freegianghu
Member
 
Registered: Oct 2004
Location: somewhere in the street
Distribution: Window$
Posts: 192

Rep: Reputation: 30
Quote:
Originally Posted by Hosiah
Code:
var ranNum= Math.round((Math.random()*5)+1);
/*var ranNum= Math.round((Math.random()%6)+1);*/
Check your html codes after save may help.

Cheers,
GH
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript Code doesnt work w/ firefox? swatward Programming 1 04-18-2005 06:54 PM
Blogger? mikeshn General 4 09-03-2004 06:49 PM
gaim-blogger! Install? Micro420 Linux - Software 2 12-17-2003 04:00 PM
How do I get javascript to work with Opera? Aerlock Linux - Software 0 11-17-2003 09:28 PM
JavaScript applets not work in Linux? Conman Linux - Newbie 2 07-27-2002 12:41 AM


All times are GMT -5. The time now is 07:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration