Code reuse?

-1

Good afternoon people! I have a question, is my logic correct? And it is possible to reduce this code or just have this way to solve ...

var aluno = new Object(){
            function adicionar_aluno{
                document.getElementById("adicionar_aluno").style.visibility
            }
            function deletar_aluno{
                document.getElementById("deletar_aluno").style.visibility
            }
            function editar_aluno{
                document.getElementById("editar_aluno").style.visibility
            }
            function consultar_aluno{
                document.getElementById("consultar_aluno").style.visibility
            }
        }
        var noticia = new Object(){
            function adicionar_noticia{
                document.getElementById("adicionar_noticia").style.visibility
            }
            function editar_noticia{
                document.getElementById("editar_noticia").style.visibility
            }
            function deletar_noticia{
                document.getElementById("deletar_noticia").style.visibility
            }
            function consultar_noticia{
                document.getElementById("consultar_noticia").style.visibility
            }
        }

My initial idea is to make when the guy clicked on a link type <a adicionar Aluno</a> reloaded on the same page an html form to add a student, I will use Ajax, right? I do not know javascript very well, but I really want to practice! Thank you in advance!

Edit 1: I would still have to do a part of courses, academic calendar etc.

    
asked by anonymous 11.09.2018 / 19:44

1 answer

0

You can create only one dynamic function for each logic you are going to do.

<a id="adicionar_aluno" onClick="adicionar(this.id);">

// funcao JS
function adicionar(elementId) {
    document.getElementById(elementId).style.visibility
}
    
11.09.2018 / 23:03