|
Posted by Tom on 01/08/07 15:03
Being a newbie to JS, I would appreciate some advice. When a visitor
enters a number into a textbox, I want to check that it is 15 digits long
and then display a message accordingly and the following script does that
OK. However, I want also to make sure that only "numbers" are entered and
no other characters. Again the attached does this but is clumsy to say the
least! How do I get it to loop back to the input box if it contains a
non-numeric, before it goes off to check for 15 digits?
<script>
var ok = " This chip will work";
var nook = "This chip will not work";
function check_input()
{
var entry = document.forms.f.textfield.value;
var length = entry.length
document.clear();
res = isNaN(entry) ? "please enter only numbers": "Press OK to continue";
alert(res);
document.write("<body bgcolor=\"44eedd\">");
document.write("<body text=\"000000\">");
document.write("<B><font size=3 face='arial'>")
if(length == 15) document.write(ok);
else
document.write(nook);
}
</script>
Any help would be greatly appreciated.
Tom
Navigation:
[Reply to this message]
|