Thread: Number control
View Single Post
03-06-2009, 12:10 AM
#2
Wildhoney is offline Wildhoney
Wildhoney's Avatar
Status: Request a custom title
Join date: Feb 2006
Location: Nottingham
Expertise:
Software:
 
Posts: 1,648
iTrader: 18 / 95%
 

Wildhoney is on a distinguished road

Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney

  Old

The following code should suffice for you. Set the ID properties on 2 objects:
  • Submit button to ID "pSubmit";
  • Input textbox to ID "pValue".

Then simply call TalkPHP_Init(); from the body onload.

Code:
function TalkPHP_Init()
{
	var pSubmit = document.getElementById('pSubmit');
	pSubmit.onclick = function() { return TalkPHP_Validate(); }
}

function TalkPHP_Validate()
{
	var iNumber = +document.getElementById('pValue').value;
	
	if (!iNumber || isNaN(iNumber))
	{
		alert('You have not entered a number.');
		return false;
	}
	
	if (iNumber < 1 || iNumber > 100)
	{
		alert('Your number must be between 1 and 100.');
		return false;
	}
	
	return true;
}