How to Add Dynamic drop-down
this is first heading
It looks like you're trying to show an input field when the user selects an option with the ID other_option from a dropdown, but there’s a small issue with your code. Specifically, id() is not a valid jQuery function. You should use .val() or .prop('id') to get the value or the ID of the selected option.
Here’s the corrected version of your code:
// Show the input field when 'Other' is selected
$('#tag_id').change(function() {
if ($(this).val() === 'other_option') {
$('#manual_tag_container').show();
} else {
$('#manual_tag_container').hide();
}
});
Explanation:
.val() gets the value of the selected option in the dropdown (#tag_id), and if the value matches 'other_option', it shows the #manual_tag_container input field.
If any other option is selected, it hides the #manual_tag_container.
Also, ensure that your option tag for "Other" has a value attribute:
<option value="other_option" id="other_option">Other</option>
JavaScript file code
The user selects an option with the ID other_option from a dropdown, but there’s a small issue with your code. Specifically, id() is not a valid jQuery function. You should use .val() or .prop('id') to get the value or the ID of the selected option.
Here’s the corrected version of your code:
// Show the input field when 'Other' is selected
$('#tag_id').change(function() {
if ($(this).val() === 'other_option') {
T$('#manual_tag_container').show();
} else {
$('#manual_tag_container').hide();
}
});
Explanation:
.val() gets the value of the selected option in the dropdown (#tag_id), and if the value matches 'other_option', it shows the #manual_tag_container input field.
If any other option is selected, it hides the #manual_tag_container.
Also, ensure that your option tag for "Other" has a value attribute:
<option value="other_option" id="other_option">Other</option>
Comments
Comments:
kundan
2025-06-10
thankyou