I want to launch the function test() if the user inputs something in the html input field with the id="sc1dc1" (without using the "onchange=" directly in HTML). What is wrong?
HTML:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<input type="text" id="sc1dc1" >
</body>
</html>
Javascript:
var x = document.getElementById("sc1dc1").value;
x.onchange = test;
function test(){alert("Test")};
valueof the element, and then address itsonchangeattribute. That is wrong. The value does not have that property. You need to remove.value. Also,onchangeonly fires when you leave the input field. If you want immediate response then useoninputinstead ofonchange.