javascript - Why won't function output into this jQuery selector? -


i'm hoping silly i've done. got function unigref near bottom, (i believe) outputs string. however, when call function build jquery selector, can't work properly. know else works because when use static string radio button selected.

here's jsfiddle/9edxx. please help.

var checkcount = 0; var maxchecks = 2;  $(document).ready(function() {  $("#test").click(function() {     alert($(':checked').length); });  $(':checkbox[name=checkbox]').change(function() {       checkcount = $(':checkbox:checked').length;      if (checkcount >= maxchecks) {       $(':checkbox[name=checkbox]').not(':checked').attr('disabled', true);           $(":radio[value="+uniqref()+"]").prop('checked', true);       } else {       $(':checkbox[name=checkbox]:disabled').attr('disabled', false);     }      if (this.checked) {         $("td.label").append("<label>" + this.value + "</label>");     } else {         $("td.label").find(":contains('" + this.value + "')").remove();     }  });  $('#button').click(function() {     alert(uniqref()); });   function uniqref() {     return $("td.label").text().split('').sort().join('').replace(/\s/g, ""); }   });​ 

update: typo has been correct, problem still exists.

http://jsfiddle.net/9edxx/

http://jsfiddle.net/7mvmt/6/

basically line:

$(":radio[value="+uniqref()+"]").prop('checked', true); 

is called prematurely (before checkbox checked. simple, ugly hack:

settimeout(function(next) {                     $(":radio[value="+uniqref()+"]").prop('checked', true);     }, 0); 

solves it.

also had typo niko mentioned.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -