1

This may be a simple and stupid question, yet I am going ahead and asking.

-----------HTML---------

<input type="button" value="Yes" class="Y" id="Yes">
 <input type="hidden" value="x1" id="a1" name="a1">


-----------JQUERY--------------

$('#RYes').click(function() {

            });

When I click on #RYes, it must save the value of #Yes and #a1 into the db. Can I write javascript into the jquery code shown above. I am using PHP/ JavaScript

3 Answers 3

2

You can do it without ajax, and without complete page reload, using an iframe. But that of course depends on your overall structure of your site. To do it with an iframe just make it into a form and change type of the button to submit as Tyler Kiser describes.

Sign up to request clarification or add additional context in comments.

Comments

0

You should be able to write and ajax call to a php page that runs the queries to save your values to the database. more info on the post method here http://docs.jquery.com/Post

1 Comment

You would need the page to reload. This means setting an action attribute on your form, or inserting the php code on the current page and checking for post information when the page loads. This also means that you can simplify the code by removing the "click" script and simply changing the input type to "submit" for the #Yes button.
0

You can do it by having a backend php script which can take these values from a POST request.

Then you could submit there values from your click function using an AJAX call. like:

$.post('your_backend.php', {'Yes' : $('#Yes').val(), 'a1' : $('#a1').val()}, function(data){});

And you can write some handler code for once the POST operation is complete in the callback function

2 Comments

well without ajax, you would require a page reload, is that acceptable?
as you are already using jquery and so javascript, why avoid ajax, it simplifies page design and is cleaner on frontend code. As for your PHP script it makes no difference as a POST is same weather from ajax, an iframe or form(with page reload)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.