-1

I was just a creating a program in JavaScript and then this error pops up. I have researched it, but all the cases seem to be different to mine. Any help would be greatly appreciated.

 function name() {
       var divi = document.getElementById('form_div');
       divi.style.display = 'none';
}
<div id='form_div'>

    <form id='div_form'>
        <input maxlength="15" style='position: center;' type="text"  placeholder="Nick" id="namebox"/>
    </form>
    
    <button onclick='name();'>Go!</button>
    <p>Type in your nick and press go!</p>
</div>

(This script element is placed before the html shown above)

Jeremy Thille
  • 26,047
  • 12
  • 43
  • 63
Oscar Peace
  • 99
  • 1
  • 2
  • 11

1 Answers1

2

The function name you have defined is giving error, if you change it the code works.

You should also avoid using the name of JavaScript built-in objects, properties, and methods. Refer: JavaScript Reserved Words

<div id='form_div'>
<form id='div_form'>
<input maxlength="15" style='position: center;' type="text"  
placeholder="Nick" id="namebox"/>
</form>
<button onclick='functionName()'>Go!</button>
<p>Type in your nick and press go!</p>
</div>
<script>
function functionName() {
   var divi = document.getElementById('form_div');
   divi.style.display = 'none';
}

</script>
Dij
  • 9,761
  • 4
  • 18
  • 35