1

I don't know where to start, if there is any similar question like mine I would be happy to get some idea! Basically the question says it all, Here is what I would like:

I have a simple dropdown menu. When a selection is made in that drop down menu, a php mysql query is ran where the database will be updated with that value. I have all the pieces, all I need is the code that would be able to kick it all off.

For instance when you hit submit on a form you would typically type out:

if (isset($_POST['submit']))
{

//grab information and insert into db

}

How would I do this for a drop down selection without having to click the submit button.

Jason
  • 13
  • 3

3 Answers3

0

Make an ajax call on drop down change like:

$('#dropdown').change(function(){
    // ajax call
});
Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
0

Use jquery/javascript onchange event to perform any type of action on the drop down list. use as follows:

$("#select_id").on('change',function(){
 $.post('code url',{paramenters to be stored},function(data){
 alert('inserted');
})
});
PHP Geek
  • 3,949
  • 1
  • 16
  • 32
0

you should be looking for something like this

<form id="testform">
<select id="yourselect" name="yourselect" onChange="updateDb()">
 <option value="somevalue">Please select</option>
 <option value="somevalue1">Something</option>
</select>
</form>

you Javascript function will look like this

function updateDb() {
// I am using jquery for ajax
 $.post("yourserverhandle.php", $("#testform").serialize());
}

and this is how your "yourserverhandle.php" looks like

<?php
$query = "update yourtable set something='".mysql_escape_string($_POST["yourselect"])."' where id='something'";
.... mysql connect, execute
?>
R.K123
  • 159
  • 2
  • 9