I have a combobox like this
after that, I have a checkbox. If the checkbox is checked, I want to copy the value of the combobox to an input of text. I write a jQuery code like this to get the value, then I set the value of combobox to an input of text
i check console to see the result.
I get the value if I check the log. But the value can’t set into input text.
But, if I make a little change in jQuery to get the key of combobox, the key can be set in the input text.
Then,in the input text I can get the key of combobox
I need help for this.
Advertisement
Answer
Your code should work. Please provide the HTML (not the templating code)
Simplified:
$("#customCheck1").on("click", function() { const text = this.checked ? $("#province option:selected").text() : ""; $("#current_province").val(text); });`
assuming unique IDs