catague Posted October 26, 2011 Report Posted October 26, 2011 hmm im new here in forum hmm and im a noob also in HTML and php program hmmm my question is how can i create a simple form that's allow user input number and automatic add ex. when a input 23+2 = 25 i hope can someone help me about this topic Thank'you in advance
mltgroup Posted October 27, 2011 Report Posted October 27, 2011 If you're looking to have it automatically add up without a page refresh or submit button clicked you'd need to use Javascript & AJAX. Otherwise your form could look like this: <form method="post" action="index.php"> <input type="text" name="field_1" /> First Number<br /> <input type="text" name="field_2" /> Second Number<br /> <input type="submit" /> </form> on the index.php file in the header you would do this: <?php $val = $_POST['field_1'] + $_POST['field_2']; echo $val; ?>
falkencreative Posted October 27, 2011 Report Posted October 27, 2011 Depends what you mean by "automatic". You would want to use Javascript if you want to automatically add the numbers together without the user clicking a button to submit the form. You would need to use Javascript's onChange event to watch for when the values in the input's change, and automatically do the calculation once both inputs have a value. If you are using PHP with a submit button, you'd need to create a form that allows users to enter numbers. When the form submits, you'd want to use $_POST[] to get the values that the visitor submitted, do the addition, and then display the calculated results back to the user.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now