Error in onclick

1

I have a form that I call the sameEmail () function in the onclick event.

<input type="checkbox" name="MesmoEmail" value="S" id="mesmoEmail" onclick="mesmoEmail();"> Mesmo e-mail do cadastro

And Javascript is this way:

<script>
function mesmoEmail(){
  alert('aqui');
  var marcado = document.getElementById('mesmoEmail');
}
</script>

The problem is that it is not working and the following error appears in the console:

Andinthesourcecode:

So far as I put the code, the word Same is in another color. I can not seem to identify the error.

    
asked by anonymous 19.08.2017 / 02:06

2 answers

1

I have identified the error. The ID has the same function name as onclick, so I made the following change:

<input type="checkbox" name="mesmoEmail" value="S" id="mesmoEmail" onclick="mesmoEmail();"> Mesmo e-mail do cadastro

To:

<input type="checkbox" name="MesmoEmail" value="S" id="mesmoemail" onclick="mesmoEmail();"> Mesmo e-mail do cadastro
    
19.08.2017 / 02:11
1

You can simplify this way:

function mesmoEmail(el){
  var marcado = el.value;
  console.log(marcado);
}
<input type="checkbox" name="MesmoEmail" value="S" id="mesmoEmail" onclick="mesmoEmail(this);"> Mesmo e-mail do cadastro
    
19.08.2017 / 02:14