i need a tips, how to make a AJAX request with mootools, when some value from a dropdown list is selected, i mean to catch this event + make a ajax request to a external php page. And on this php page i need to run a mysql query. Thanks.
<form name ="f1" action=""> <select id="myr" NAME ="s1" onChange = "GetSelectedItem()"> <OPTION VALUE = "meshed" selected >-- Please Select --</OPTION> <OPTION VALUE = "girls">Male seeking Female</OPTION> <OPTION VALUE = "mens">Female seeking Male</OPTION> <OPTION VALUE = "mens">Male seeking Male</OPTION> <OPTION VALUE = "girls">Female seeking Female</OPTION> </select> </form> php
$dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); $dbname = 'ratings'; mysql_select_db($dbname) or die('Error connecting to database'); $sql = "TRUNCATE TABLE rabid_ratings"; $re = mysql_query($sql) or die(mysql_error()); echo "done"; mootools
<script type="text/javascript"> window.addEvent('domready',function(){ var myRequest = new Request({ url: 'truncate.php', method: 'post', onRequest: function(){ }, onSuccess: function(responseText){ alert("done!"+ responseText); }, onFailure: function(){ alert("failed"); } }); $('myr').addEvent('change', function(event){ event.stop(); myRequest.send(); }); }); </script>