Im doing a small project at work. This needs an input form that accepts only (+) plus (-) minus, with a resulting out put of 1 for plus and 0 (zero) for minus.
Creating a form to input numbers using plus sign and negative sign.
Collapse
X
-
Try this code.
Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Positive Negative Zero</title> </head> <body> <form method="post"> <input type="text" placeholder="Input Number" name="input" value="<?=$_POST['input']?>"> <input type="submit" name="submit"> </form> <?php if(isset($_POST['submit'])) { $input = $_POST['input']; if($input>0) { echo 'Your input is Positive'; } else if($input<0) { echo 'Your input is Negative'; } else if($input==0) { echo 'Your input is Zero'; } } ?> </body> </html>
-
what I had tried to ask, was I create a form to be used in science project, where results are entered as either positive
or negative. But the out put should generate the 1 for positive and the number 0 (zero) for negative.
Not sure if that tries to explain my reasoning.
ThanksComment
Comment