Something amis with passing a keyCode to a function

M

Matthew

Still getting my webfeet on in understanding the proper syntax for
crafting javascript statements. I've created this function that
ignores the code if the Tab key is pressed... oddly enough it works
just fine in IE and ignores the Tab key like I want it too, but in
Netscape it blows up.... I don't think the Tab key is being passed or
something else is amis. ???


<script type="text/javascript">
function showRemaining(formElement) {
if ((event.keyCode) != 9) {
var theForm1 = formElement.form;
var remainingDisplay = formElement.name + 'Remaining';
theForm1.elements[remainingDisplay].value = formElement.maxLength
- formElement.value.length;
}}
</script>




<input... onkeyup="javascript:showRemaining(this);"
 
L

Lasse Reichstein Nielsen

Still getting my webfeet on in understanding the proper syntax for
crafting javascript statements. I've created this function that
ignores the code if the Tab key is pressed... oddly enough it works
just fine in IE and ignores the Tab key like I want it too, but in
Netscape it blows up.... I don't think the Tab key is being passed or
something else is amis. ???


<script type="text/javascript">
function showRemaining(formElement) {
if ((event.keyCode) != 9) {

Where does the event variable come from? (In IE, it is a global variable,
in most remining browsers and W3C DOM 2 Events, it is not).

I suggest making the event a parameter of the function, i.e.,
---
function showRemining(evt,formElement) {
if (evt.keyCode != 9) {
---

and then:
<input... onkeyup="javascript:showRemaining(this);"

<input ... onkeyup"showRemaining(event,this);">

No "javascript:" in front (why did you think it should be there?),
and pass the event to the function.

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,781
Messages
2,569,616
Members
45,305
Latest member
KetoMeltsupplement

Latest Threads

Top