samedi 2 mai 2015

If Input Value equals to DIV's ID, then show it

I'm trying to create simple dictionary web-page and I need to show certain DIV with word's translation and description which is entered in INPUT.

I've created some simple JavaScript for that, but I want to use about 50 words and not planning to create 50 scripts for that :D.

var match = 'cat',
    input = document.getElementById('searchbox'),
    div = document.getElementById('cat');
    input.onkeyup = function(e){
    if (this.value == match){
        div.style.display = 'block';
    }
    else {
        div.style.display = 'none';
    }
};  

Instead of that I want to use something different. My goal is to achieve something like that - If text entered in INPUT equals to one my DIV's ID than show it.

For example if visitor typed "CAT" in INPUT than show DIV with "CAT" ID and so on. One script instead of 50 :D.

P.S. - I'm beginner in code, so sorry for those kind of question. :D

Aucun commentaire:

Enregistrer un commentaire