Thread: Resolved Won't append to the array
View Single Post
Old 09-29-2012, 07:44 PM   PM User | #4
akzes
New to the CF scene

 
Join Date: Sep 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
akzes is an unknown quantity at this point
Thanks Phillip! That really cleared up a HUGE error.

So I got it working, except its putting 'den' into the array twice, it should only go in once its checked off, and when it becomes unchecked, should remove 'den' from the array.

Any suggestions?

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script type="text/javascript">
var chosen=[];
var feat=function(chosenfeat){
	if (chosenfeat==="den"){
		if (chosen.indexOf("den",1)===1){ //CHANGED IT RIGHT HERE!
			document.getElementById('denid').checked=false;
			alert("Are you sure you don't want a Den? They are free!");
			chosen.splice(chosen.indexOf("den",1))
			console.log(chosen);}
		else {
			chosen.push("den");
			alert("Congradulations! You recieve a complimentary free den!");
			console.log(chosen);}
		
		}
		}
</script>
</head>
<body>
<input type="checkbox" id="denid"  onclick="feat('den');" />Den (NO CHARGE)<br />
</body>
</html>
They taught us in school that indexOf is ok...I guess not lol. No one uses IE9 :P ahaha
akzes is offline   Reply With Quote