0

This is for a menu. jArray4[i] is what appears on the button.
No matter what is selected data: {'action': ''+jArray4[i]+''}, results in the last button being selected. I am new to Jquery so I don't know how to properly pass the correctly selected button.

var object = {   
  text : ''+(jArray4[i]) +'',
  onselect : function() {
    jQuery.ajax({
      type: "POST",
      dataType: "json",
      url: 'ajaxreturn.php',
      data: {'action': ''+jArray4[i]+''},
      success: function(json)
      {
        alert(json.first);
      }
    });        
  }
};
options.push(object);
Sandcastle.addToolbarMenu(options);
Barmar
  • 741,623
  • 53
  • 500
  • 612
exploregis
  • 101
  • 2
  • depends on how you're assigning `i`. And you don't need the single quotes `''` – A. L Jun 23 '17 at 01:28
  • Can you tell us what your `jArray4` looks like? – Brett East Jun 23 '17 at 01:45
  • jArray4 looks like [ "'s-Hertogenbosch,Netherlands", "Aalborg,Denmark", "Aarau,Switzerland", "Aba,Nigeria", "Abadan,Iran", "Abadan,Iraq", "Abakan,Russia", "Abbotsford,Canada", "Abeokuta,Nigeria", "Aberdeen,United Kingdom", 2063 more… ] – exploregis Jun 23 '17 at 02:05
  • Its working now, the answer was "let i=0" instead of "var i=0" – exploregis Jun 23 '17 at 02:38

0 Answers0