1

I have a script that will show a dropdown box when a td(table data) is clicked. It contains options 'X' and 'O'.

my html table contains data in my data base. My client wants a front-end editing of data because that's easy for them. So i made the td transform to dropdown so that they can put remarks easily. But how can i save to database the changes that users made in table.

Here is my script to make td a dropdown box :

$(document).on('click', 'td', function() { ////---make td transform to dropdown list box when click---///
  if($(this).find('select').length == 0) {
      $(this).empty();  //clears out current text in the table
      $(this).append('<select><option></option><option style="font-size:20px;">X <option style="font-size:20px;">O</select>');
  }
});
2
  • try to call function using Ajax on change option of select box Jun 13, 2019 at 5:52
  • 1
    can you make a sample for that.
    – Gelxxxx
    Jun 13, 2019 at 5:54

1 Answer 1

0

Add Name and Class to your select box

$(document).on('click', 'td', function() { 
if($(this).find('select').length == 0) 
  {
    $(this).empty();  //clears out current text in the table
    $(this).append('<select class="selectbox" name="selectbox"><option></option><option 
style="font-size:20px;" value="X">X <option value="0" style="font-size:20px;">O</select>');
  }
});

and create a jquery change event, Try something like this

 $(document).on('change', '.selectbox', function() { 
    $.ajax({
      type: 'POST',
      crossDomain: true,   
      data: {
        data_value: this.value,
      },   
      url: 'your_url_to_update_to_db.php',
      success: function (data) 
      { 
          //do Something
        },
      });
  });
5
  • how can i replace the value of the td by the selected remarks in select box to database? can you give sample for the update.php?
    – Gelxxxx
    Jun 13, 2019 at 7:28
  • "UPDATE mbwa, mbwa_2 SET mbwa.DAY1 = mbwa.DAY1, mbwa_2.DAY1_A =mbwa_2.DAY1_A WHERE mbwa.employeeName = mbwa_2.employeeName" -- i only tried this by first td(table data) in each two rows of my html table... and it doesn't work. Value of td is coming back and doesn't update when page reload.
    – Gelxxxx
    Jun 13, 2019 at 23:42
  • something like mbwa.DAY1 = 'the selected value in selection box'...... so that value will replace by the selected option,,
    – Gelxxxx
    Jun 13, 2019 at 23:53
  • Update your question with full Code of your update.php, I will check it Jun 14, 2019 at 3:58
  • see this question stackoverflow.com/questions/56592312/…
    – Gelxxxx
    Jun 14, 2019 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.