W3C home > Mailing lists > Public > www-html@w3.org > December 1998

Re: Any way to input numerical/integer data in form?

From: <kgeorge@tcpsoft.com>
Date: Tue, 22 Dec 1998 04:33:56 -0500 (EST)
Message-ID: <367F669E.79CEAB05@tcpsoft.com>
To: Scott Calbert <SCalber@doa.state.la.us>
CC: "'www-html@w3.org'" <www-html@w3.org>

  The reason that numbers in a web page are essentially text strings
representing numbers.  When you enter "432" in a text box those are the
characters '4' (52), '3' (51), and '2' (50).  Now you might ask, "Why
doesn't the browser (or why isn't there a feature to) convert the text
string to a number before the form is posted?"  The reason is because
form data needs to be posted using text strings.  This was the way http
and html were designed.  However, it is not too hard to convert the
ascii string "432" to the integer 432.  Assuming that "432" is a null
terminated string and is not url-encoded (i.e., not in "%" encoding ..
"432" could also be represented as "%34%33%32") you can apply the
following to obtain the integer value:

(btw, this is also assuming that the value is unsigned .. no '-'
character in front of the "432")

unsigned int     strtoint(char *p)
  int            x = 0;

  while  (*p) {
    if (!isdigit(*p)) 
    x = (x * 10) + (*p - '0');

  return (x);

then again, this is really unnecessary because the standard library
itoa() will work just fine.  (I'm assuming you're coding in C/C++ .. if
not, oh well).

Hope this helps.

Kyle George

Scott Calbert wrote:
> Wondering if anyone has a trick for inputing data that exists as an integer
> via a web form without having to go through conversion measures after entry?
> Wouldn't an INPUT TYPE="number" or "integer" tag be nice so you get the
> correct type of data from the beginning of the process?  I need to do
> sorts/calculations on numbers input from the web, but it treats them as text
> data, and I'm thusfar unable to find a successful conversion procedure.
> Thanks for the help.
Received on Tuesday, 22 December 1998 05:07:14 UTC

This archive was generated by hypermail 2.4.0 : Thursday, 30 April 2020 16:20:35 UTC