473,462 Members | 1,350 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Creating a form to input numbers using plus sign and negative sign.

3
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.
Mar 10 '15 #1

✓ answered by Exequiel

Try this code.
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Positive Negative Zero</title>
  6. </head>
  7.  
  8. <body>
  9. <form method="post">
  10. <input type="text" placeholder="Input Number" name="input" value="<?=$_POST['input']?>">
  11. <input type="submit" name="submit">
  12. </form>
  13.  
  14. <?php 
  15. if(isset($_POST['submit']))
  16. {
  17.     $input = $_POST['input'];
  18.  
  19.     if($input>0)
  20.     {
  21.         echo 'Your input is Positive';
  22.     }            
  23.     else if($input<0)
  24.     {
  25.         echo 'Your input is Negative';
  26.     }        
  27.     else if($input==0)
  28.     {
  29.         echo 'Your input is Zero';
  30.     }
  31. }
  32. ?>
  33. </body>
  34. </html>
  35.  

5 1751
Exequiel
288 256MB
Try this code.
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Positive Negative Zero</title>
  6. </head>
  7.  
  8. <body>
  9. <form method="post">
  10. <input type="text" placeholder="Input Number" name="input" value="<?=$_POST['input']?>">
  11. <input type="submit" name="submit">
  12. </form>
  13.  
  14. <?php 
  15. if(isset($_POST['submit']))
  16. {
  17.     $input = $_POST['input'];
  18.  
  19.     if($input>0)
  20.     {
  21.         echo 'Your input is Positive';
  22.     }            
  23.     else if($input<0)
  24.     {
  25.         echo 'Your input is Negative';
  26.     }        
  27.     else if($input==0)
  28.     {
  29.         echo 'Your input is Zero';
  30.     }
  31. }
  32. ?>
  33. </body>
  34. </html>
  35.  
Mar 11 '15 #2
Please clarify your question more clearly as you want code to built a form in which language HTML or any other. so that I will help you out.
Mar 11 '15 #3
Dormilich
8,658 Expert Mod 8TB
you want code to built a form in which language HTML or any other.
is there any form that does not consist of HTML?
Mar 11 '15 #4
ciro07
3
I need to create a using HTML, Im just a beginner and trying to teach
myself, html and php. thanks in advance.
Mar 12 '15 #5
ciro07
3
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.

Thanks
Mar 18 '15 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: skubik | last post by:
I'm curious as to whether it's possible to create a Form object and populate it with form element objects, strictly in Javascript, without the need to apply the form to a document. Essentially,...
2
by: phpuser32423 | last post by:
Hi everyone Is it by any chance possible to use mysql and php to auto create the content for drop-down lists on forms by retrieving the values from a database? The reason i ask is that on a site...
6
by: neelay1 | last post by:
Hi all, I have a Javascript variable that contains the name of a form input- input_name = "document.myform.ip" How can I get the value of this form input, "ip" using the variable input_name?...
8
by: Phil Latio | last post by:
I've been creating an application over the last few weeks and generally pleased with what I have produced but one area is irritating me, form validation. At the moment the forms are simply...
4
by: GeekBoy | last post by:
I am reading a file of numbers using for loops. The numbers are in a grid as follows: 8 36 14 11 31 17 22 23 17 8 9 33 23 32 18 39 23 25 9 38 14 38 4 22 18 11 31 19 16 17 9 32 25 8 1 23
6
by: penny | last post by:
In this assignment we shall look at a possible representation of rational numbers in java using objects. The java language represents rational numbers using the same representation used for other...
1
by: Amy Badgett | last post by:
I would like to create a form that allows users to enter in changes in transactions of inventory. Is there any way the number entered into a control text box can automatically have a negative...
2
KeredDrahcir
by: KeredDrahcir | last post by:
I have a form and I'm using CSS3 to use the form input type "email". This seems to make sense since any browser that doesn't support it would default to text which is what I would otherwise use,...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.