| re: Changing value of text fields not inside form
songkau wrote:[color=blue]
> Why doesn't this work? :-
>
> <BODY onkeydown="display(event)">
> <input type="text" name="text1">
> <script language="Javascript">
> function display(event) {
> document.text1.value = event.keyCode+' : '+String.fromCharCode(event.keyCode);
> }
> </script>
> </BODY>
>
> Error: document.text1 has no properties
>
> I have to put it in a Form to get it to work :-
>
> <BODY onkeydown="display(event)">
> <form name="form1">
> <input type="text" name="text1">
> </form>
> <script language="Javascript">
> function display(event) {
> document.form1.text1.value = event.keyCode+' : '+String.fromCharCode(event.keyCode);
> }
> </script>
> </BODY>[/color]
It is OK to put form controls into an HTML page without making
them part of a form. However, if you do, you don't have access
to certain features that are available when they are part of a
form. For example, they can never be successful and so can't be
submitted as if they were in a form.
Have a read here:
<URL:http://jibbering.com/faq/faq_notes/form_access.html>
--
Rob |