Jquery Click not the first click

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(); }); 
+8
jquery forms click
source share
6 answers

Unable to replicate

I dealt with this and could not replicate it: http://jsfiddle.net/DCM48/

Please download the full script with the question for further assistance.

-Lededje

+2
source share

try using delegate

 $(document).ready(function() { $("body").delegate("click", ".text_choice_button", function() { your code...... }); }); 
+1
source share

I'm having trouble with the onclick handign usign jquery handler. I find mousedown a more reliable solution. The kind of click capture I find better. http://api.jquery.com/mousedown/

0
source share

I always use this template, maybe you should try it.

 $(element).click(function() {}); 

Also write here the html code in which you use javascript for.

0
source share
 $(function(){ $("body").click("a, div", function(){ $("body").append("ping"); }); }); 
0
source share

try to live

 $(".text_choice_button").live('click', 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(); }); 
-3
source share

All Articles