I have a simple form whereby an input field is given a value if a certain button is clicked. The problem is it takes to long to reload the page and I would like to submit it without refreshing the page. I have tried adapting certain AJAX,JQuery scripts from different types but they haven’t worked, can anyone suggest a some simple code to use. Here is the basic example:
<html>
<form method='POST' action='test2.php'>
<input type='text' name='input_a' value='<?php if($_POST['submit_a'])
{
echo "test1";
} ?>'>
<input type='submit' name='submit_a' value='a'>
<input type='text' name='input_b' value='<?php if($_POST['submit_b'])
{
echo "test2";
}?>'>
<input type='submit' name='submit_b' value='b'>
</form>
</html>
I adapted this using vanilla javascript only, if the use case really is this basic. If server side access is needed, this solution will not help, and you’re going to have to learn more about how Ajax works.
HTML:
Javascript:
Here is the example working in JSFiddle:
http://jsfiddle.net/6jpNf/1/