Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Function to write in seperate div's writes in all, help?

    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?

    Code:
    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.
    Last edited by Toxhicide; 12-19-2010 at 05:11 AM.

  • #2
    New Coder
    Join Date
    Dec 2010
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Ive tried to edit the checkValue() function, but this doesnt seem to help in any way either.

    Code:
    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]+"'>"
    }
    }
    Last edited by Toxhicide; 12-18-2010 at 07:20 PM.

  • #3
    New Coder
    Join Date
    Dec 2010
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I was able to solve it myself, I added return to every if else statement.

    Code:
    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
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •