Click to See Complete Forum and Search --> : Textbox, Integer?


IsmAvatar
01-10-2004, 11:27 PM
Just wondering, is there some way to confine the user to only typing in numbers in a textbox, and to go a bit further, if I can, to make sure the number is no less than 0, and is not a fraction or decimal (an integer, I believe you call them)?

<form>
<input type="text" value="0" size=1 maxlength=3 />
</form>

yeah, would that use the onBlur event, or could you stop them before they event type it?

if this is javascript, then go ahead and move it, I just figured it's html since it's inside of tags.

PeOfEo
01-10-2004, 11:35 PM
You cant stop them before they type it, but yuo can use java script (or preferably a server side script) to give them an error message when the submit.

IsmAvatar
01-10-2004, 11:58 PM
(or preferably a server side script)
err, what? what's a 'server side script'?

PeOfEo
01-11-2004, 12:08 AM
ASP PHP CGI ASP.NET JSP CF etc. They are scripts executed by the server instead of by the browser.

Khalid Ali
01-11-2004, 08:29 AM
Just a thought, If I were to fill that form and I took some time fill it in and then submit it only to find out that data was wrongly entered,I seriously won't bother again unless I have to , have to do that.

A better option if available, in this particular situation will be to use JavaScript and warn user then and their before they spent 5 minutes in completing the form.

pyro
01-11-2004, 10:26 AM
<form action="">
<p><input type="text" name="foo" onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }"></p>
</form>But remember, users can disable JavaScript.

PeOfEo
01-11-2004, 11:52 AM
That is why it is important to have server side scripts just incase, so users can't just turn off java script and send it anyway, say run it on button click.

IsmAvatar
01-12-2004, 03:34 PM
most of the page is javascript, and it's not a form where they submit stuff, it's just a form that modifies how the page appears. if they don't have javascript, there's no point in viewing the page. pyro, I'll try that.

Edit: I tried it, and, it works, but if they use the keyboard loop, it doesn't catch it. press and hold "a".

<form>
<input type="text" name="z" value=1 size=1 maxlength=3 onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }" />
</form>