0

now im making form using PHP code. I combine with ajax code. inside the form contain input type="radio", <textarea></textarea> and dropdown list.

i create ajax code like this

$.ajax({
        url: 'index.php?route=data/save',
        type: 'post',
        data: $('#save-method input[type=\'radio\']:checked, #save-method textarea, #save-method option:selected'),
        dataType: 'json',

when debug it. i able to get name and value for radio and textare. but for dropdown, im only able to get the value.

{
  data: {
          room: "room.4", 
          undefined: "2021-03-26", 
          comment: "please ontime"
        }
}
  • "room" is radio name
  • "comment" is textarea name
  • but for dropdown it display "undefined".

i set the dropdown like this

<select name="set_schedule" > 
      <option value="2021-03-26">2021-03-26</option> 
      <option value="2021-03-27">2021-03-27</option> 
</select>

how do i able to get dropdown name using my ajax code.

please help

ferdinand
  • 325
  • 2
  • 14
  • Because you only fetch the selected option, you don't get the whole `select` element. An `option` element doesn't have a name, only the whole `select` does. So when you fetch your option, you need to get its parent and then get the name from there. – El_Vanja Mar 26 '21 at 12:07
  • Hi, are you sure this `$('#save-method input[type=\'radio\']:checked, #save-method textarea, #save-method option:selected')..` is giving you above output ? – Swati Mar 26 '21 at 12:53

0 Answers0