first off not asking anyone to do my work for me just help me work out why something isnt working.
The problem was after i removed the html code for the buttons in favor of a loop to create them, the id for each line created in the loop matchs that on the subroutines button name so it should work. but it dont for the life of me i cant work out why. all the buttons do come up on screen just do nothing although the code to disable and enable them seems to work so it can pick up the id names il also include that code as that code does work.
if i cant get this working i have to revert to other code which will mean i earn less marks but i cant understand why this isnt working
Here is the code in question also theres a dropbox link if anyone wants to use that.
Code:
<html>
<head>
<title>Animal Garden</title>
</head>
<body background="background3.jpg">
<center>
<img src="Header.png" /><br />
<div id="fuzzy" align="center"></div>
<div id="star" align="center"></div><br />
<input id="btnrandom" type="button" value="?" />
<p id="par1"></p>
<p id="par2"></p>
</center>
<object id="animalsound" classid="clsid:6bf52a52-394a-11d3-b153-00c04f79faa6" style="width:0px; height:0px;"></object>
</body>
</html>
<script language="vbscript">
option explicit
dim animal(7), previous, rand(1), button, correct(4), count(1), stars(5), num(1), green, red, stopstart
sub window_onload()
dim i, star, animals
Do
i = i + 1
Star = Star & "<img id=star" & i & " " & "src=Star/StarOff.gif />"
Loop Until i = 5
document.getElementById("star").innerHTML = Star & document.getElementById("star").innerHTML
i = 0
Do
'once solved work out if onclick=function() can use vbscript
i = i + 1
animals = animals & "<button id='btnanimal" & i & "' style='padding: 0px 0px;'><img src='Animals/Animal" & i & ".jpg'" & " " & "width='200' height='150' /></button>"
Loop Until i = 7
document.getElementById("fuzzy").innerHTML = animals & document.getElementById("fuzzy").innerHTML
disable
count(0) = 0
count(1) = 0
par2.innertext = "Please Start By Clicking the ? Button"
previous = "nothing"
animal(1) = "Damselfly"
animal(2) = "Frog"
animal(3) = "Hedgehog"
animal(4) = "Newt"
animal(5) = "Slowworm"
animal(6) = "Thrush"
animal(7) = "Butterfly"
stars(0) = "Star/StarOff.gif"
stars(1) = "Star/StarOff.gif"
stars(2) = "Star/StarOff.gif"
stars(3) = "Star/StarOff.gif"
stars(4) = "Star/StarOff.gif"
stars(5) = "Star/StarOff.gif"
green = "border: 8px solid green; padding: 0px 0px;"
red = "border: 8px solid red; padding: 0px 0px;"
end sub
sub btnrandom_onclick()
par1.innertext = ""
par2.innertext = "Try Pick the Right Picture for this Animal"
rand(0) = cint(rnd()*6+1)
rand(1) = animal(rand(0))
if rand(1) = previous then
Do
rand(0) = cint(rnd()*6)
rand(1) = animal(rand(0))
Loop until rand(1) <> previous
previous = rand(1)
else
previous = rand(1)
end if
animalsound.URL = "Animals/Animal" & animal(rand(0)) & ".wav"
btnrandom.disabled = "disabled"
disable
border
end sub
sub border
dim i
Do
i = i + 1
document.getElementById("btnanimal" & i).style.border=""
loop until i = 7
end sub
sub btnanimal1_onclick()
num(0) = 1
button = animal(num(0))
rightwrong
end sub
sub btnanimal2_onclick()
num(0) = 2
button = animal(num(0))
rightwrong
end sub
sub btnanimal3_onclick()
num(0) = 3
button = animal(num(0))
rightwrong
end sub
sub btnanimal4_onclick()
num(0) = 4
button = animal(num(0))
rightwrong
end sub
sub btnanimal5_onclick()
num(0) = 5
button = animal(num(0))
rightwrong
end sub
sub btnanimal6_onclick()
num(0) = 6
button = animal(num(0))
rightwrong
end sub
sub btnanimal7_onclick
num(0) = 7
button = animal(num(0))
rightwrong
end sub
sub rightwrong()
animalsound.URL = "Animals/Animal" & animal(num(0)) & ".wav"
if button = rand(1) then
par2.innertext = "Correct"
document.getElementById("btnanimal" & rand(0)).style.border="thick solid green"
count(0) = count(0) + 1
stars(count(1)) = "Star/StarOn.gif"
count(1) = count(1) + 1
else
document.getElementById("btnanimal" & num(0)).style.border="thick solid red"
document.getElementById("btnanimal" & rand(0)).style.border="thick solid green"
par2.innertext = "Incorrect"
par1.innertext = rand(1)
end if
disable
if count(0) = 5 then
dim Response
animalsound.URL = "Animals/Animal" & animal(num(0)) & ".wav"
star5.src = "Star/StarOn.gif"
par2.innertext = ""
btnrandom.disabled = "disabled"
par1.innertext = ""
Response = MsgBox("Well Done You Have Finished The Game",0)
If Response = vbok Then
reset
border
End If
else
btnrandom.disabled = ""
end if
starpics
end sub
sub starpics
star1.src = stars(0)
star2.src = stars(1)
star3.src = stars(2)
star4.src = stars(3)
star5.src = stars(4)
end sub
sub reset()
rand(1) = ""
num(0) = ""
animalsound.URL = ""
par1.innertext = ""
btnrandom.disabled = ""
count(0) = 0
count(1) = 0
par2.innertext = "Please Start By Clicking the ? Button"
stars(0) = "Star/StarOff.gif"
stars(1) = "Star/StarOff.gif"
stars(2) = "Star/StarOff.gif"
stars(3) = "Star/StarOff.gif"
stars(4) = "Star/StarOff.gif"
starpics
disable
disable
end sub
sub disable
dim j
if stopstart = "disabled" then
stopstart = ""
else
stopstart = "disabled"
end if
Do
j = j + 1
document.getElementById("btnanimal" & j).disabled = stopstart
loop until j = 7
end sub
failing that here is a dropbox link
http://www.facebook.com/l.php?u=http%3A ... =LAQFVlWge
_________________
I am not online much if you wish to get hold of me send me a private message with your email/discord and ill catch up with you.