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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding up form values and disabling non numeric and decimal keys

Status
Not open for further replies.

zippynz

Programmer
May 17, 2001
50
NZ
Hi, I am using this script to add up the contents of a form, It works great except it won't accept a decimals input.
That is because a friend disabled all other characters, what I need to do though is enable the decimal key so it will allow you to enter a decimal,

thanks in advance :)
Code:
function add(){ 
	var form = window.frmMain;
	form.Total.value = parseFloat(cBlankToZero(form.cents20.value)) + parseFloat(cBlankToZero(form.cents50.value)) + parseFloat(cBlankToZero(form.dollar1.value)) + parseFloat(cBlankToZero(form.dollars2.value)) + parseFloat(cBlankToZero(form.dollars5.value)) + parseFloat(cBlankToZero(form.dollars10.value)) + parseFloat(cBlankToZero(form.dollars20.value)) + parseFloat(cBlankToZero(form.dollars50.value)) + parseFloat(cBlankToZero(form.dollars100.value));
}

function numericOnly(){
	if (window.event.keyCode < 48 || window.event.keyCode > 57){
		window.event.returnValue = false;
	}
}

function cBlankToZero(x){
	if (x==&quot;&quot;)
		return 0;
	else
		return x;
}
 
nevermind i figured it out myself
Code:
function numericOnly(){
	if (window.event.keyCode < 46 || window.event.keyCode > 57){
		window.event.returnValue = false;
	}
	if  (window.event.keyCode == 47){
		window.event.returnValue = false;
	}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top