I have a text field in which I need to set the value when the user either selects an option from the selection field or enters text in the text field and gets into the link. Both events then close the div that contains the selection and the text box / link.
Selection function works
$(document).on("change", ".select_choice", function(event) { var string = $(this).find("option:selected").text(); $(this).closest(".select_toggle_area").find(".toggle_choices").toggle(); $(this).closest(".select_toggle_area").find(".target_input").val(string); });
The text box / link works in the second click. Each time something is entered into the field, the link does not work on the first click. It hides the div, but does not update the value of the target field.
$(document).on("click", ".text_choice_button", function(event) { event.preventDefault(); var string = $(this).closest(".select_toggle_area").find(".text_choice").val(); $(this).closest(".select_toggle_area").find(".target_input").val(string); $(this).closest(".select_toggle_area").find(".toggle_choices").toggle(); });
jquery forms click
Gabe K
source share