dniwebdesign

05-29-2009, 02:41 AM

I have this form entry <input type="text" onkeypress="return numbersonly(this,event); lessthan100(this);" name="discount_value" id="discount_value" value="" style="width: 40%;" maxlength="3" class="input-symbol-parent"> which calls two javascript functions. The first one works without a hitch... no letters can be entered into the field. However the next function (which at present time, just contains an alert) doesn't fire and I get no alert.

I need to check if it's a number first. Below is the number checker. :-)

function iscontrolkey(key) {

if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ||

(key==63232) || (key==63233) || (key==63234) || (key==63235) || (key==63272)) return true;

else return false;

}

function numbersonly(myfield, e) {

var key;

var keychar;

if (window.event) key = window.event.keyCode;

else if (e) key = e.which;

else return true;

keychar = String.fromCharCode(key);

if (iscontrolkey(key)) return true;

// numbers or decimal

else if ((("0123456789.").indexOf(keychar) > -1)) return true;

else return false;

}

I need to check if it's a number first. Below is the number checker. :-)

function iscontrolkey(key) {

if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ||

(key==63232) || (key==63233) || (key==63234) || (key==63235) || (key==63272)) return true;

else return false;

}

function numbersonly(myfield, e) {

var key;

var keychar;

if (window.event) key = window.event.keyCode;

else if (e) key = e.which;

else return true;

keychar = String.fromCharCode(key);

if (iscontrolkey(key)) return true;

// numbers or decimal

else if ((("0123456789.").indexOf(keychar) > -1)) return true;

else return false;

}