...

View Full Version : Resolved Function to write in seperate div's writes in all, help?



Toxhicide
12-18-2010, 02:33 AM
So Im trying to make it so my button writes in one box when I click it one time, another when I click it a second, etc, but when I click it once, it writes in all boxes. Why is this?


content += "<br><input type='text' value='' id='d1' name='d1'><br>"
content += "<input type='button' value='random card' id='r1' name='r1' onclick='randomCard()'>"
content += "<div id='c1' name='c1'></div><div id='c2' name='c2'></div><div id='c3' name='c3'></div><div id='c4' name='c4'></div><div id='c5' name='c5'></div><div id='c6' name='c6'></div><div id='c7' name='c7'></div><div id='c8' name='c8'></div><div id='c9' name='c9'></div><div id='c10' name='c10'></div><div id='c11' name='c11'></div>"


function checkValue(){
if (c1.innerHTML == ""){
c1.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
} else{
if (c1.innerHTML != "" && c2.innerHTML == ""){
c2.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML == ""){
c3.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML == ""){
c4.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML == ""){
c5.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML == ""){
c6.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML == ""){
c7.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML == ""){
c8.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML == ""){
c9.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML != "" && c10.innerHTML == ""){
c10.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML != "" && c10.innerHTML != "" && c11.innerHTML == ""){
c11.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML != "" && c10.innerHTML != "" && c11.innerHTML != ""){
alert('How in the **** did you get more than eleven cards?')
} else{
}
}
}
}
}
}
}
}
}
}
}
}
}


function randomCard(){
for (c=0;c<DCard.length;c++){
randCard = DCard[Math.floor(Math.random()*DCard.length)]
document.getElementById('c1').value = randCard

c1 = document.getElementById('c1')
c2 = document.getElementById('c2')
c3 = document.getElementById('c3')
c4 = document.getElementById('c4')
c5 = document.getElementById('c5')
c6 = document.getElementById('c6')
c7 = document.getElementById('c7')
c8 = document.getElementById('c8')
c9 = document.getElementById('c9')
c10 = document.getElementById('c10')
c11 = document.getElementById('c11')

checkValue()
}
}

Not my whole code, but the necessary parts.

Toxhicide
12-18-2010, 04:23 PM
Ive tried to edit the checkValue() function, but this doesnt seem to help in any way either.


function checkValue(){
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML != "" && c10.innerHTML != "" && c11.innerHTML != ""){
alert('How in the **** did you get more than eleven cards? Thats impossible.')
}
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML != "" && c10.innerHTML != "" && c11.innerHTML == ""){
c11.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
}
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML != "" && c10.innerHTML == ""){
c10.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
}
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML == ""){
c9.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
}
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML == ""){
c8.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
}
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML == ""){
c7.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
}
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML == ""){
c6.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
}
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML == ""){
c5.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
}
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML == ""){
c4.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
}
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML == ""){
c3.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
}
if (c1.innerHTML != "" && c2.innerHTML == ""){
c2.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
}
if (c1.innerHTML == ""){
c1.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>"
}
}

Toxhicide
12-19-2010, 04:22 AM
I was able to solve it myself, I added return to every if else statement.


function checkValue(){
if (c1.innerHTML == ""){
c1.innerHTML = "<img src='"+cUrl+DCard[count][0]+cExt+"' alt='"+DCard[count][1]+"'>"
return
} else{
if (c1.innerHTML != "" && c2.innerHTML == ""){
c2.innerHTML = "<img src='"+cUrl+DCard[count][0]+cExt+"' alt='"+DCard[count][1]+"'>"
return
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML == ""){
c3.innerHTML = "<img src='"+cUrl+DCard[count][0]+cExt+"' alt='"+DCard[count][1]+"'>"
return
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML == ""){
c4.innerHTML = "<img src='"+cUrl+DCard[count][0]+cExt+"' alt='"+DCard[count][1]+"'>"
return
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML == ""){
c5.innerHTML = "<img src='"+cUrl+DCard[count][0]+cExt+"' alt='"+DCard[count][1]+"'>"
return
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML == ""){
c6.innerHTML = "<img src='"+cUrl+DCard[count][0]+cExt+"' alt='"+DCard[count][1]+"'>"
return
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML == ""){
c7.innerHTML = "<img src='"+cUrl+DCard[count][0]+cExt+"' alt='"+DCard[count][1]+"'>"
return
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML == ""){
c8.innerHTML = "<img src='"+cUrl+DCard[count][0]+cExt+"' alt='"+DCard[count][1]+"'>"
return
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML == ""){
c9.innerHTML = "<img src='"+cUrl+DCard[count][0]+cExt+"' alt='"+DCard[count][1]+"'>"
return
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML != "" && c10.innerHTML == ""){
c10.innerHTML = "<img src='"+cUrl+DCard[count][0]+cExt+"' alt='"+DCard[count][1]+"'>"
return
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML != "" && c10.innerHTML != "" && c11.innerHTML == ""){
c11.innerHTML = "<img src='"+cUrl+DCard[count][0]+cExt+"' alt='"+DCard[count][1]+"'>"
return
} else{
if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML != "" && c10.innerHTML != "" && c11.innerHTML != ""){
alert('How in the **** did you get more than eleven cards?')
return
}
}
}
}
}
}
}
}
}
}
}
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum