...

View Full Version : alert on wrong data type



rafiki
09-01-2006, 01:45 AM
need an alert to pop up when some1 try's to input somthin other than a number into my form so if they try type a into age it will alert then that i want numerical input

_Aerospace_Eng_
09-01-2006, 02:56 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function isNum()
{
var thetest = document.forms[0].nums;
thetest.setAttribute('autocomplete','off');
if(!thetest.value.match(/^\d+$/))
{
alert('You can only enter numbers');
thetest.value = '';
thetest.focus();
}
}
</script>
</head>

<body>
<form action="#" method="post">
<input type="text" name="nums" onKeyUp="isNum()" size="3" maxlength="3">
</form>
</body>
</html>

rafiki
09-01-2006, 01:51 PM
aero that not working do i need 2 edit anything?

_Aerospace_Eng_
09-01-2006, 07:09 PM
Post the code you are using and I'll let you know. You do need to change var thetest to match your input name. In the code I posted the input name is nums. Please try using proper English and complete sentences.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum