Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnChange help

Status
Not open for further replies.

Jussi7

Vendor
Feb 2, 2006
3
FI
I'm trying to post this form as soon as the user pastes something into the textbox, this code doesn't work:

Code:
<script type="text/javascript">
function sendForm() {
document.form1.submit();

}

document.getElementByName['ean'].focus();

function target(){document.form1.ean.focus();}

</script>
</head>

<body onLoad=target();>
<form name="form1" method="post" action="barcode.php">
<p>
<input type="text" name="ean" onChange="sendForm()">
</p>
</form>
 
The onchange event only fires once focus has left the field the event is set on. So this method is not going to fire as soon as they paste something but only after they paste and then move to the next field.

Also, getElementByName is not a valid method.
The actual method would be getElementsByName and this returns a collection of objects with that name, not a single object so you would have to access that collection as an array to determine which object you want to modify the focus property on.
You are better off giving the field an ID and using document.getElementById which will work for what you intended.



Stamp out, eliminate and abolish redundancy!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top