Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>EDIT: here is a solution that works quite well for the task, adapting the lines of Tvanfosson:</p> <pre><code>&lt;script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"&gt; &lt;/script&gt; &lt;script&gt; $(function() { $('#country').change( function() { var val = $(this).val(); if (val == 223 || val == 224) { $('#othstate').val('').hide(); $.ajax({ url: 'findState.php', dataType: 'html', data: { country : val }, success: function(data) { $('#state').html( data ); } }); } else { $('#state').val('').hide(); $('#othstate').show(); } }); }); &lt;/script&gt; &lt;select style="background-color: #ffffa0" name="country" id=country &gt; &lt;option&gt;Select Country&lt;/option&gt; &lt;option value="223"&gt;USA&lt;/option&gt; &lt;option value="224"&gt;Canada&lt;/option&gt; &lt;option value="225"&gt;England&lt;/option&gt; &lt;option value="226"&gt;Ireland&lt;/option&gt; &lt;/select&gt; &lt;select style="background-color: #ffffa0" name="state"&gt; &lt;option&gt;Select Country First&lt;/option&gt; &lt;/select&gt; &lt;input type="text" name="othstate" id=othstate value="" class="textBox" style="display: none;"&gt; </code></pre> <p>As you can see, I eliminated the <code>&lt;form&gt;</code> element which is not absolutely necessary but can be added (and then has to be used properly in case JS is deactivated at the users end. See <a href="https://stackoverflow.com/questions/2704753/is-form-tag-necessary-in-ajax-web-application"> here</a>.</p> <p>I also eliminated the <code>onchange</code> event which is being replaced by the 'change()` jquery function.</p>
    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.
    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