X10nD
X10nD

Reputation: 22030

Clicking a simple HTML button to write into DB via jQuery / Javascript & PHP

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

Upvotes: 1

Views: 475

Answers (3)

rrostt
rrostt

Reputation: 172

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.

Upvotes: 2

danishgoel
danishgoel

Reputation: 3645

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

Upvotes: 0

Tyler Kiser
Tyler Kiser

Reputation: 921

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

Upvotes: 0

Related Questions