Something amis with passing a keyCode to a function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew

    #1

    Something amis with passing a keyCode to a function

    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(f ormElement) {
    if ((event.keyCode ) != 9) {
    var theForm1 = formElement.for m;
    var remainingDispla y = formElement.nam e + 'Remaining';
    theForm1.elemen ts[remainingDispla y].value = formElement.max Length
    - formElement.val ue.length;
    }}
    </script>




    <input... onkeyup="javasc ript:showRemain ing(this);"
  • Lasse Reichstein Nielsen

    #2
    Re: Something amis with passing a keyCode to a function

    mattsimc@yahoo. com (Matthew) writes:
    [color=blue]
    > 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(f ormElement) {
    > if ((event.keyCode ) != 9) {[/color]

    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(ev t,formElement) {
    if (evt.keyCode != 9) {
    ---

    and then:
    [color=blue]
    > <input... onkeyup="javasc ript:showRemain ing(this);"[/color]

    <input ... onkeyup"showRem aining(event,th is);">

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

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...