471,573 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,573 software developers and data experts.

Changing value of text fields not inside form

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>
Jul 23 '05 #1
1 1446
songkau wrote:
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>

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
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by horos | last post: by
4 posts views Thread by Tony W | last post: by
2 posts views Thread by sheldonlg | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.