jquery - get select options from php in x editable


I am using x editable for inline editing.


  value: 2,
  source: [
  {value: 1, text: 'Active'},
  {value: 2, text: 'Blocked'},
  {value: 3, text: 'Deleted'}

This one is running fine. But the problem is, I want to get source options fromphp. For that I have an array.


$php_array = Array ( [MOBILE_TOPUP] => MOBILE_TOPUP
                     [PICKUP] =>PICKUP
                     [DELIVERY] => DELIVERY
                     [BANK_DEPOSIT] => BANK_DEPOSIT )

I tried with by passing below variable in source but it's not working:

var json_array = <?=json_encode($php_array)?>;

How can I achieve this? Do I need to change array structure inPHP? Thanks for any help!




Yes, you have to change array structure as below :

$php_array = Array ( 
        array('value' => 1, 'text' => 'Active'),
        array('value' => 2, 'text' => 'Blocked'),
        array('value' => 3, 'text' => 'Deleted'),

var json_array = '<?=json_encode($php_array)?>';



You shouldn't use PHP inside JS, better to make an ajax call. This feature is built into x-editable if you use thesource option with a string like so:

  value: 2,
  source: 'mypage.php'

People are also looking for solutions to the problem: mysqli - php update dynamic sql rows through form


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.