lerro;10989799 wrote:
Take it that you have buttons for a calculator, the user clicks a button at a time and the button clicked has its value stored in the variable "input"
Are you certain this isn't allready handled by the environment? For example, there is PHP code on the server handling this form post, but as I type, there is nothing reaching that script. The browser does however let me type several characters into this textarea element.
lerro;10989799 wrote:
so that input can be set to blank/null, ready for teh next character that the user clicks
And I'd be highly annoyed if the textarea I'm typing into right now would never contain more than one character at the time.
lerro;10989799 wrote:
Function setNumber()
{
storedNumber = storedNumber & input;
output = storedNumber;
input = Null;
}
And there are several issues with this as well. First off, it doesn't appear to be PHP code. If it is PHP code, those constants has to be defined somewhere, and it's common practice to keep constants in upper case letters, and also, you can't assign data to a constant.
If they are supposed to be variables, other than needing a $ as starting character of the identifier, they will still have to be defined somewhere. storedNumber might of course be defined as static $storedNumber in the function. $input on the other hand should definitely NOT be a global, but be a function paramter.
Also note that $storedNumber & $input will not do what you are talking about earlier in your post. & is the binary and operator. For example, 3 & 1 = 1, 3 & 2 = 2, 3 & 0 = 0 and 3 & 3 = 3.
lerro;10989799 wrote:
Now, once the user clicks one button at a time, how would you append a period into the variable "storedNumber" ?
$stuff .= $input;
lerro;10989799 wrote:
Also, how would this apply if you wanted it strictly typed and not loosely typed
PHP is loosely typed so you'd have to switch to a language which isn't such as Java or C++.
lerro;10989799 wrote:
, so that the variable could not take any non-numeral characters but would hold a double?
That can still be dealt with, but just because you restrict input doesn't mean you make PHP strictly typed.
if (is_numeric($input)) || $input == '.')