|
Manipulating the Value of a Text FieldMouse over the links below the text field and see what happens. This magic is performed by changing the value of the text field. The form looks like the one in the last example: <FORM
NAME="form1"> The links that change the text field are: NOTE: javascript:void(null)
or javascript:void("") or
javascript:void('') or javascript:void(0) <A HREF="javascript:void(null)" <A HREF="javascript:void(null)" These are normal mouseovers; the important part is: document.form1.text1.value='Clap clap!'. This says, "find the form called form1 in the document, find the form element called text1, and set its value to 'Clap clap!'." The second line works similarly. This is very much like changing the src of an image. Instead of having a src, text fields have values. Other types of form elements can be affected by messing with their values - for example, TextAreas: The forms and links here are very similar to those above. The form is: <FORM NAME="form2"> Notice that the form has a name, form2, and the textarea has a name as well, theTextarea. The links are basically the same as what you saw in the text field example: <A HREF="javascript:void(null)" <A HREF="javascript:void(null)" The only difference is that instead of assigning a string to the value of the <TEXTAREA>s, I assigned variables that I defined in the header. View Source to see that they're there. I only did this for the sake of neatness, to get those long strings out of the HTML. Here's one of the strings: var Part1 = "Now I'm the king of the
swingers\n Notice the "\n". In general, because you're working with HTML, the new line isn't important. But if you're writing something in a <PRE> tag, or you're writing into a textarea, the "\n" comes in handy. In addition to changing the values of form elements, JavaScript allows you to detect events that go on inside of them. Here's an example of detecting events inside a text field. |