onKeyDown not working with Firefox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Star
    New Member
    • Dec 2010
    • 1

    onKeyDown not working with Firefox

    Ohhh Firefox.... I have created a javascript that when you click in a box to update a value, the submit button grays out and the update buttons is active. This works fine in IE and Safari as well as if i call the javascript from a drop down menu onChange it works fine, just when i do a onKeyPress or onKeyDown. I have been doing research on this all morning and getting tired of it. The closest thing i found was doing something like this, but i can not figure out how to get it to work with my script.


    Code:
    function EnterKey(e)
    {
         var key;
         if(window.event)
              key = window.event.keyCode;     //IE
         else
              key = e.which;     //firefox
               
         if(key == 13)
              return true;
         else
              return false;
    }
    Here is my input...

    Code:
    <input size="2" tabindex="2" onkeydown="validate();" onblur="setFocus()"  type="text" maxlength="3" name="qty<?php echo $prod_key; ?>" value="<?php echo $qty; ?>"/>

    Here is my javascript to gray out the submit button and show the update button.
    Code:
    function validate( the_form ) {  
    
    	var x=document.getElementById('update');
    	var y=document.getElementById('sale_pass');	
    	var z=document.getElementById('reason');
    	var hide=document.getElementById('hide');
    	var hide_r=document.getElementById('hide_r');
    	var sale=document.getElementById('sale_type');
    	var car=document.getElementById('complete');
    	
    	car.disabled = true;
    	x.style.visibility = 'visible';
    	if(sale.value != 'sale') {
    	    y.style.visibility = 'hidden';
    		z.style.visibility = 'hidden';
    		hide.style.visibility = 'hidden';
    		hide_r.style.visibility = 'hidden';
    	}
    	//x.focus();
    }
    </script>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    probably something like
    Code:
    // input is your input element
    input.onkeydown = EnterKey;
    
    // somewhere inside EnterKey() you have to call validate()

    Comment

    Working...