Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/02/2021 in all areas

  1. This example will repopulate the category menu depending on the selected type <html> <head> <title>Sample</title> <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script type='text/javascript'> // array of categories for each type var cat_types = JSON.parse('{"A":{"1":"Cat 1","2":"Cat 2","3":"Cat 3"},"B":{"4":"Cat 4","5":"Cat 5","6":"Cat 6"},"C":{"7":"Cat 7","8":"Cat 8","9":"Cat 9"}}'); $().ready(function() { // populate type menu $.each(cat_types, function(k,v) { $("#type").append($("<option>", {"val":k, "text":k})) }) // when type selected, populate cat menu $("#type").change( function() { $("#cat").html("<option value=''> - select category -</option"); var type = $(this).val() $.each(cat_types[type], function(k, v) { $("#cat").append($("<option>", {"val":k, "text":v})) }) }) }) </script> <style type='text/css'> </style> </head> <body> <form> Type <select name='type' id='type'> <option value=""> - select type -</option> </select> <br><br> Cat <select name='cat' id='cat'></select><br> </form> </body> </html>
    1 point
  2. For completeness, I should state that an alternative method to the above is to use fetch() Here is an alternative script section using fetch instead of $.get() <script type='text/javascript'> $().ready( function() { $("#find").click( function() { var tid = $("#tid").val() fetch('?ajax=teacher&tid='+tid) .then(response => response.json()) .then(data => handleOutput(data)) }) }) function handleOutput(resp) { $.each(resp, function(k,v) { $("#"+k).val(v) }) } </script>
    1 point
  3. Wife is from Dublin -- have always enjoyed visiting. Brother in law spent a few years in Australia -- sorry we didn't visit them when they were there. Best of luck with the business idea!
    1 point
  4. People always say why reinvent the wheel? The best answer to that, because by reinventing the wheel you understand it better. Rather than just use JQuery to get the job done by writing the whole thing yourself in javascript you're much better off understanding it.
    1 point
This leaderboard is set to New York/GMT-05:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.