Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, if you are with <code>Drupal</code>&amp; <code>PHP</code> it's easy to do.<br> Try with something like:</p> <pre><code>&lt;?PHP // First, get the selected value in a $var $food_type = $_REQUEST['field_type_value']; ?&gt; </code></pre> <p>Then, you can use a loop for the options or just add to each a condition like:</p> <pre><code>&lt;select id="edit-field-type-value" name="field_type_value" class="form-select"&gt; ... &lt;option value="Chinese" &lt;?PHP if($food_type == 'Chinese')echo 'selected="selected"'; ?&gt;&gt;Chinese&lt;/option&gt; ... &lt;/select&gt; </code></pre> <hr> <p>But... If the options are injected with <code>jQuery</code>... you will need to convert that <code>PHP $var</code> to <code>javascript var</code> like:</p> <pre><code>&lt;?PHP $food_type = $_REQUEST['field_type_value']; echo '&lt;script&gt;var food_type = "'.$food_type.'";&lt;/script&gt;'; ?&gt; </code></pre> <p>And then in JS loop...</p> <pre><code>var food_type_loop = ["Type of Restaurant...", "Chinese", "Indian", "more..."]; // all your options jQuery(document).ready(function(){ for (var i=0 ;i&lt;food_type_loop.length; i++) { $("#edit-field-type-value").append("&lt;option value='" + food_type_loop[i] + "'&gt;" + food_type_loop[i] + "&lt;/option&gt;").val(food_type_loop[i]); // reach to the end... now select th proper one if(i+1 == food_type_loop.length) select_the_food(); } }); function select_the_food(){ $('#edit-field-type-value option[value="'+food_type+'"]').prop('selected', true); } </code></pre> <h3>Fiddle example with jQ <a href="http://jsfiddle.net/gmolop/hWKkL/1/" rel="nofollow">http://jsfiddle.net/gmolop/hWKkL/1/</a></h3>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload