-2

i want to make an input disappear if javascript is disabled, i have tried,

<script>
document.getelementbyid('mydiv').innerhtml= <input type=text>;
</script>
<div id="mydiv"></div>

so that if javascript is disabled the code will not put the input in the div
but in my browser console it says document.getelementbyid('myinput') is undefined, but if i put in a function my browser console doesn't say anything is there a way i can make a function run immediately the page is loaded or to make the input show only when javascript is enabled

webing
  • 25
  • 7
  • Just place the script after the element, and correct the spelling of the properties. – Teemu Jun 22 '20 at 11:42
  • _“but in my browser console it says document.getelementbyid('myinput') is undefined”_ - because the element did not exist already at that point, where you tried to access it here. Change the order, so that the `script` element comes _after_ the element you are trying to access. – CBroe Jun 22 '20 at 11:43

2 Answers2

1

I think you wanna do this. Notice the spell corrections:

<div id="mydiv"></div>
<script>
document.getElementById('mydiv').innerHTML= '<input type=text>';
</script>
ABGR
  • 3,606
  • 1
  • 15
  • 35
0

JavaScript is case sensitive, so getelementbyid is not the same as getElementById.

The correct function is document.getElementById.

The same problem with innerhtml. It should be innerHTML.

Also <input type=text> should be in quotes, because it is a string.

<div id="mydiv"></div>
<script>
  document.getElementById('mydiv').innerHTML= '<input type="text">';
</script>
habiiev
  • 386
  • 1
  • 9