0
<!DOCTYPE html>
<html>
    <body>
        <p>Click the button".</p>
        <input type="text" name="demo" id="demo" value="">
        <button value="button" onclick="alert(document.getElementById("demo").value);">Click me</button>
    </body>
</html>

This code is not working but document.getElementById("demo").value replace "this.value" getting result "button".

may be any syntax error or this way of onclick is not working?

simon
  • 1,180
  • 3
  • 12
  • 33
Balaguru Murugan
  • 463
  • 2
  • 7
  • 21

1 Answers1

0

Use single quotes instead and that will works.

<!DOCTYPE html>
<html>
<body>
<p>Click the button".</p>
<input type="text" name="demo" id="demo" value="">
<button value="button" onclick="alert(document.getElementById('demo').value);">Click me</button>
</body>
</html>
Adnan Umer
  • 3,669
  • 2
  • 18
  • 38