Domanda

I have a toggle with in my php that I would like to use to simply change a value in a mysql table. Far as I know, it is simply an element of a form, but how can I POST that ON/OFF value just by switching, without using a 'submit' method?

 <input data-no-uniform="true" type="checkbox" class="iphone-toggle">

for now it is an input element with fancy CSS to make this checkbox into a slide switch. SO if the switch has a default state and simply sliding the switch or "checking the box" would be enough to change the value in a cell. where is the submission in that?

Hope that makes sense....

È stato utile?

Soluzione

As you are using jQuery, you can do something like:

$('.iphone-toggle').on('change', function() {
  var toggle_data = $(this).data('no-uniform')
      toggle_value = $(this).val();

  $.ajax({
    type: "POST",
    url: 'your_url.php',
    data: {toggle: toggle_data, value: toggle_value},
    success: function() {
      // what you do on success
    }
  });
});

And in php you will have the values of $_POST['toggle'] and $_POST['value'] to make the correct database query.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top