Hayes
05-16-2012, 03:39 PM
Hi all me again :thumbsup:
I have this bit of code:
<script type="text/javascript">
var testvar = "<? print $cards; ?>";
var name = "<? print $name; ?>";
//Create JavaScript array
var testarray = new Array();
//Fill JavaScript array from the converted string
testarray = testvar.split(":#:");
var imagesleft = 10;
var numclicks = 0;
var score = 0;
function clickCard (what,where)
{
var count=0;
for(var x = 0; x < testarray.length; x++)
{
if(what == testarray[x])
{
count++;
}
}
if(count==1)
{
alert("unique");
document.images[where].src = "./images/blank.png";
imagesleft--;
score = score+20;
clicks.innerHTML = "Unique Images to find = " + imagesleft;
if(imagesleft==0)
{
score = score - numclicks;
var r=confirm("Do you want to enter your score in the highscore table?");
if (r==true)
{
document.getElementById('score').value = score;
document.forms["highscore"].submit();
}
else
{
var t=confirm("Do you want to play again?");
if (t==true)
{
document.location.reload();
}
else
{
window.close();
}
}
}
}
else
{
alert("Not unique");
}
numclicks++;
pairs.innerHTML = "Number of Clicks = " + numclicks;
}
</script>
which works a treat but when it is put into a external js file all I get is the alert Not unique and nothing else! any ideas why?
I have this bit of code:
<script type="text/javascript">
var testvar = "<? print $cards; ?>";
var name = "<? print $name; ?>";
//Create JavaScript array
var testarray = new Array();
//Fill JavaScript array from the converted string
testarray = testvar.split(":#:");
var imagesleft = 10;
var numclicks = 0;
var score = 0;
function clickCard (what,where)
{
var count=0;
for(var x = 0; x < testarray.length; x++)
{
if(what == testarray[x])
{
count++;
}
}
if(count==1)
{
alert("unique");
document.images[where].src = "./images/blank.png";
imagesleft--;
score = score+20;
clicks.innerHTML = "Unique Images to find = " + imagesleft;
if(imagesleft==0)
{
score = score - numclicks;
var r=confirm("Do you want to enter your score in the highscore table?");
if (r==true)
{
document.getElementById('score').value = score;
document.forms["highscore"].submit();
}
else
{
var t=confirm("Do you want to play again?");
if (t==true)
{
document.location.reload();
}
else
{
window.close();
}
}
}
}
else
{
alert("Not unique");
}
numclicks++;
pairs.innerHTML = "Number of Clicks = " + numclicks;
}
</script>
which works a treat but when it is put into a external js file all I get is the alert Not unique and nothing else! any ideas why?