Change a Form Field with Javascript
To change a form field with Javascript:
function sayHey() {
fo.el.value="Fill it in, dog!";
}
<FORM name=fo>
<input type=text name=el>
</FORM>
<a href="#" onMouseOver="javascript:sayHey()">Mouse Over Me, Please</a>
First, I'll explain our FORM:
-We named our form
fo because we like short names.
-We named our text field
el because we like easy to type names.
Next, I'll explain our function:
-We created a
function and named it
sayHey().
---the first section needs the form name which we named
fo
---the second section needs the form element name which we named
el
---the third section is the word
value which means we are about to say what we want
fo.el to equal.
Lastly:
-We created a link and used
onMouseOver to
call our function.
When we onMouseOver, the text field will fill with our text "Fill it in, dog!".
Free Copy and Paste Javascript Code:
<script type="text/javascript">
<!--
function sayHey() {
fo.el.value="Fill it in, dog!";
}
-->
</script>
<form name=fo>
<input type=text name=el>
</form>
<a href="#" onMouseOver="javascript:sayHey()">Mouse Over Me, Please</a>
Resources:
Use OnMouseOver in Javascript
Create a Function in Javascript
Call your Function in Javascript
Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
| | | |
| | | CSS David McFarland |
| | | |