Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Mobile Show/Hide Form input based on select field
    text
    copied!<p>I have the following form fields on my jQuery Mobile page. I want to initially hide the element, and then have it .show() if the user selects the option with value="Other"</p> <p>Here's my HTML:</p> <pre><code>&lt;div data-role="fieldcontain" class="no-field-separator"&gt; &lt;select name="plan_height" id="plan_height" data-native-menu="false"&gt; &lt;option&gt;Plan Height&lt;/option&gt; &lt;option value="Standard 6foot 2inch"&gt;Standard 6'2"&lt;/option&gt; &lt;option value="Other"&gt;Specify in Notes&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div id="specify_plan_height_box" style="display:none;"&gt; &lt;div data-role="fieldcontain" class="ui-hide-label no-field-separator"&gt; &lt;label for="specify_plan_height"&gt;Specify Plan Height&lt;/label&gt; &lt;input type="text" id="specify_plan_height" name="specify_plan_height" placeholder="Specify Plan Height" maxlength="50" /&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>and here's my JS INSIDE the page:</p> <pre><code> // $( '#machine-guarding-page' ).live( 'pageinit',function(event) { $( document ).bind( "pageinit", function( event, data ) { $('#plan_height').change(function() { var planHeightVal = $("#plan_height option:selected").val(); var sphb = $("#specify_plan_height_box"); sphb.hide(); if (planHeightVal == "Other") { sphb.show(); } }); }); }); </code></pre> <p>It works fine here in this <a href="http://jsfiddle.net/Qe6G4/" rel="nofollow">working example</a>. Do I need to have something other than <code>$(".page").live('pageinit', function() {</code> at the top of my JS code to make it work after the page loads? It works fine in the example link above, but not on my jQuery Mobile site.</p>
 

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