Title: using jQuery
Last modified: November 23, 2019

---

# using jQuery

 *  Resolved [salisburycamra](https://wordpress.org/support/users/salisburycamra/)
 * (@salisburycamra)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/using-jquery-2/)
 * I’m trying to create a dependant select using jQuery. The example I have used
   is here – [http://www.lisenme.com/dynamic-dependent-select-box-using-jquery-ajax-php/](http://www.lisenme.com/dynamic-dependent-select-box-using-jquery-ajax-php/).
   Creating this outside WP works fine and linking to the built-in jQuery files 
   works. I have replaced the ‘$’ with ‘jQuery’ but the script doesn’t work. Is 
   there a problem using jQuery?
 *     ```
       <select name="Brewery" id="brewery_id" tabindex="1">
       <option selected disabled value="">--- Select Brewery ---</option>
       <?php foreach ($wpub_breweries as $wpub_result)
           {
            echo '<option value="' . $wpub_result->BreweryCode . '">' . 
                                   $wpub_result->QualifiedBreweryName . '</option>' . "\r\n\t\t\t\t\t\t";
                                   }
       ?>
       </select>
       <select name="Beer" id="beer_id">
       <option value="">Select Brewery first</option>
       </select>
       <script>
       jQuery(document).ready(function(){
           jQuery('#brewery_id').on('change',function(){
               var BreweryID = jQuery(this).val();
               if(BreweryID){
                   jQuery.ajax({
                       type:'POST',
                       url:'ajaxData.php',
                       data:'BreweryCode='+BreweryID,
                       success:function(html){
                           jQuery('#beer_id').html(html);
                       }
                   }); 
               }else{
                   jQuery('#beer_id').html('<option value="">Select Brewery first</option>');
               }
           });
       </script>
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [salisburycamra](https://wordpress.org/support/users/salisburycamra/)
 * (@salisburycamra)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/using-jquery-2/#post-12220178)
 * Just in case anyone has a similar problem, I found the error which was the url
   for ajaxdata.php needs to be defined in full. No additional js files need to 
   be defined, WP already has what is needed.
 *  Thread Starter [salisburycamra](https://wordpress.org/support/users/salisburycamra/)
 * (@salisburycamra)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/using-jquery-2/#post-12220183)
 * Resolved

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘using jQuery’ is closed to new replies.

 * ![](https://ps.w.org/insert-php-code-snippet/assets/icon-128x128.png?rev=1800967)
 * [Insert PHP Code Snippet](https://wordpress.org/plugins/insert-php-code-snippet/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-php-code-snippet/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-php-code-snippet/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-php-code-snippet/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-php-code-snippet/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-php-code-snippet/reviews/)

## Tags

 * [jquery](https://wordpress.org/support/topic-tag/jquery/)
 * [select](https://wordpress.org/support/topic-tag/select/)

 * 2 replies
 * 1 participant
 * Last reply from: [salisburycamra](https://wordpress.org/support/users/salisburycamra/)
 * Last activity: [6 years, 4 months ago](https://wordpress.org/support/topic/using-jquery-2/#post-12220183)
 * Status: resolved