Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP foreach loop, unique <select> id for getElementById
    primarykey
    data
    text
    <p>What I am interested in getting is $option_value['price'] in a string from the dropdown, not . Using .value returns the later.</p> <p>I have select menus that are created in a foreach() loop. The drop downs will hold price options. I am trying to give each product it's own id so I can use the javascript onChange() function to update prices on the screen.</p> <p>The select tag looks like this: </p> <pre><code> &lt;select name="option[&lt;?php echo $option['product_option_id']; ?&gt;]" class="select_options" id="select_&lt;?php echo $product['product_id']; ?&gt;" onchange="getIt(this);"&gt; </code></pre> <p>and the javascript:</p> <pre><code>function getIt(el) { var id = el.id; a = document.getElementById(id).text; alert(a); } </code></pre> <p>Alerting out id gives me select_some number. So I can see that it is getting the id. but alerting out a gives me [object HTMLSelectElement].</p> <p>so I tried </p> <pre><code>alert(a.options.selectedIndex.value); </code></pre> <p>and get unidentified.</p> <pre><code>&lt;?php if ($product['options']) { ?&gt; &lt;div class="options" id="option_&lt;?php echo $product['product_id']; ?&gt;"&gt; &lt;?php foreach ($product['options'] as $option) { ?&gt; &lt;?php if ($option['type'] == 'select') { ?&gt; &lt;div id="option-&lt;?php echo $option['product_option_id']; ?&gt;" class="option select_option"&gt; &lt;select name="option[&lt;?php echo $option['product_option_id']; ?&gt;]" class="select_options" id="select_&lt;?php echo $product['product_id']; ?&gt;" onchange="getIt(this);"&gt; &lt;option value=""&gt;&lt;?php echo $text_select; ?&gt;&lt;/option&gt; &lt;?php foreach ($option['option_value'] as $option_value) { ?&gt; &lt;option value="&lt;?php echo $option_value['product_option_value_id']; ?&gt;"&gt;&lt;?php echo $option_value['name']; ?&gt; &lt;?php if ($option_value['price']) { ?&gt; (&lt;?php echo $option_value['price_prefix']; ?&gt;&lt;span id="newPrice"&gt;&lt;?php echo str_replace('.00','.',$option_value['price']); ?&gt;&lt;/span&gt;) &lt;?php } ?&gt; &lt;/option&gt; &lt;?php } ?&gt; &lt;/select&gt; &lt;/div&gt; &lt;?php } ?&gt; </code></pre>
    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. 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