I’m working on a project for new students to sign up for courses. I want the fees to show up right away when they pick a course. I tried some jQuery but it’s not doing what I want. Here’s what I’ve got so far:
I’ve encountered a similar issue before, and I can offer a slightly different approach that might be helpful. Instead of using an object, you could create a data attribute in your HTML for each option. This method can be particularly useful if you need to store multiple pieces of information for each course.
$('#program-choice').change(function() {
var fee = $(this).find(':selected').data('fee');
$('#cost-display').text('$' + fee);
});
This approach allows you to easily add more data attributes in the future if needed, such as course duration or start dates, without changing your JavaScript logic. It’s also quite performant as it doesn’t require object lookups.
This way, it’s super easy to add new courses or change prices without touching the main logic. Plus, it’ll work for all your courses, not just Data Management.
What do you think? Have you tried something like this before? I’m curious to hear if you’ve found any other cool ways to handle dynamic form stuff!