catague Posted October 26, 2011 Report Share 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 Quote Link to comment Share on other sites More sharing options...
mltgroup Posted October 27, 2011 Report Share 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; ?> Quote Link to comment Share on other sites More sharing options...
falkencreative Posted October 27, 2011 Report Share 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.