i m learning PHP.How can i insert a data in mysql by using onchange event in radio button, i m not used a submit button in my code can u help me by giving a solution of my prolblem by giving a little example.

Thank you so much

Edited by sonalchavda

2 Years
Discussion Span
Last Post by mmcdonald

This is pretty straight-forward and is usually easier than most people think. What I would do is call a function in the onchange attribute. In the following example the onchange attribute will be watching a dropdown, so the function will be called upon when the value of the dropdown changes:

<select onchange="myFunction()">

Then in my script I could have a javascript function with a jQuery AJAX block:

function myFunction(){
    $.ajax({url:"script.php", success:function(result){

        something here to output the result, like a div update.


Then in script.php validate and execute your SQL query. The need to call upon another script arises from Javascripts inability to communicate with the server, unless you're using node.js, which is a totally different kettle of fish. Javascript is a client side language and everything it does is completed in the users browser. By using jQuery's Ajax we can call upon a server side script from the users browser when a change is made.

I hope this makes sense, but I didn't have much from you to work with.

See more: http://api.jquery.com/jquery.ajax/


Edited by mmcdonald


You have to use a Javascript (or jQuery) AJAX to call a PHP script to perform a MySQL insert.

Sorry Pritaeas - you posted your response whilst I was typing mine :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.