I have an HTML file that includes a JavaScript. I would like this JavaScript to be able to create an "onChange=<func tion>" attribute against the password element.
Here is an example page of the onChange embedded in the "password" field. This is normal HTML and it works fine.
However, I would like to be able to add the "onChange" method by JavaScript. This way I can dynamically change the method being used. Here is my attempt at getting it to work. This does not work but shows what I am trying to do.
Here is an example page of the onChange embedded in the "password" field. This is normal HTML and it works fine.
Code:
<HTML>
<HEAD><TITLE> Example of onChange Event Handler </TITLE>
</HEAD>
<BODY BGCOLOR="FFFFFF" TEXT="000000">
<H3>Example of onChange Event Handler</H3>
<form method="post">
Name: <input type="text" name="name" size=10><br>
Pass: <input type="password" name="password" size=10 onChange='alert("It WORKED!")'><br>
<input type="submit" name="submit" size=10 >
</form>
<P>
</BODY>
</HTML>
Code:
<HTML>
<HEAD><TITLE> Example of onChange Event Handler </TITLE>
<SCRIPT LANGUAGE="JavaScript">
document.forms[0].elements[1].onChange='alert("It WORKED!")';
</SCRIPT>
</HEAD>
<BODY BGCOLOR="FFFFFF" TEXT="000000">
<H3>Example of onChange Event Handler</H3>
<form method="post">
Name: <input type="text" name="name" size=10><br>
Pass: <input type="password" name="password" size=10 ><br>
<input type="submit" name="submit" size=10 >
</form>
<P>
</BODY>
</HTML>
Comment