Note that there are some explanatory texts on larger screens.

plurals
  1. POShow/hide dynamic textbox based on pulldown
    primarykey
    data
    text
    <p>I'm trying to figure out how to have jQuery show/hide a dynamically generated textbox based on a pulldown menu selection. My JS skills are extremely limited. I have the following created in a while loop, depending on the number of people:</p> <pre><code>&lt;select name="location[&lt;?=$pid?&gt;]" id="location[&lt;?=$pid?&gt;]"&gt; &lt;option value="&lt;?=$loc_id?&gt;" selected&gt;&lt;?=$loc_name?&gt; &lt;/option&gt; &lt;option value="Other"&gt;Other&lt;/option&gt; &lt;option value="Other"&gt;--------&lt;/option&gt; &lt;? $query_loc = mysqli_query($link, "SELECT * FROM locations WHERE loc_app = 'Y' ORDER BY loc_name ASC"); while($fetch_loc = mysqli_fetch_array($query_loc)){ $loc_id = $fetch_loc['loc_id']; $loc_name = $fetch_loc['loc_name']; ?&gt; &lt;option value="&lt;?=$loc_id?&gt;"&gt;&lt;?=$loc_name?&gt;&lt;/option&gt; &lt;? } ?&gt; &lt;/select&gt; &lt;input name="location_other[&lt;?=$pid?&gt;]" type="text" id="location_other[&lt;?=$pid?&gt;]" style="display:none" /&gt; </code></pre> <p>jQuery function:</p> <pre><code>&lt;script type='text/javascript'&gt; $(window).load(function(){ $('#location').change(function () { if ($(this).val() == "Other") { $('#location_other').show(); } else { $('#location_other').hide(); } }); }); &lt;/script&gt; </code></pre> <p>I need to keep the id of the and the serialized with the $pid variable for later processing. Is there another way to call the jquery function on these?</p> <p>The HTML output looks like this:</p> <pre><code>&lt;select name="location[287]" id="location[287]"&gt; &lt;option value="1" selected&gt;A&lt;/option&gt; &lt;option value="Other"&gt;Other&lt;/option&gt; &lt;option value="Other"&gt;--------&lt;/option&gt; &lt;option value="12"&gt;B&lt;/option&gt; &lt;option value="12"&gt;C&lt;/option&gt; &lt;/select&gt; &lt;input name="location_other[287]" type="text" id="location_other[287]" style="display:none" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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