简体   繁体   中英

hide div when isset on input

I met a trouble with a script I'm doing,

In fact it does not work.

What I would like to do is to make draggable some divs, and to put there content into an iput type text. For that I wrote a function like that:

function checkdiv()
    {
      var position1= document.getElementById("position1").value;
        if(position1=="1")
        {
         document.getElementById("1").style.display = "none"                        
        }
        if(position1==2)
        {
         document.getElementById("2").style.display = "none"                        
        }
        if(position1==3)
        {
         document.getElementById("3").style.display = "none"                        
        }
        if(position1==4)
        {
         document.getElementById("4").style.display = "none"                        
        }    
        if(position1==5)
        {
         document.getElementById("5").style.display = "none"                        
        }
        if(position1==6)
        {
         document.getElementById("6").style.display = "none"                        
        }
        if(position1==7)
        {
         document.getElementById("7").style.display = "none"                        
        }
        if(position1==8)
        {
         document.getElementById("8").style.display = "none"                        
        }                 
        if(position1==9)
        {
         document.getElementById("9").style.display = "none"                        
        }  
        if(position1==10)
        {
         document.getElementById("10").style.display = "none"                        
        }             
        if(position1==11)
        {
         document.getElementById("11").style.display = "none"                        
        }     
        if(position1==12)
        {
         document.getElementById("12").style.display = "none"                        
        }    
        if(position1==13)
        {
         document.getElementById("13").style.display = "none"                        
        }            

    }
       checkdiv();    ​

But it does not really work.

I would like to make disappear div when they a re put into input and to make come them back if the input is set empty or with an other content.

Here is the jsfiddle. http://jsfiddle.net/FqM4A/13/

receive all my utmost Respect.

Kind Regards.

SP.

There were quite a few issues there, the HTML is very outdated, but I presume this is just a learning exercise, see working code here:

http://jsfiddle.net/FqM4A/22/

Note that IDs for elements shouldn't start with a number.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM