Click here to Skip to main content
15,886,003 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI Exports


i am facing difficult in the java-script,i am not getting how to carry on with this problem

my problem is

i have form where i am having country code , short country code , and check box


like
C#
countryCode shortcountrycode    check box

  1                  USD
  2                  INR
  3                  USD


now if i checked the no 1 check box the java-script should work like it should automatically check the 3rd check box because NO 1 and 3rd Checkbox shortcountrycode is same (USD).

Check-Box are generated dynamically

how to achieve it please help me
Posted
Updated 11-Sep-14 23:28pm
v3

See this example on jsfiddle. But I didn't check any condition. As you mentioned you can set it by using the checkbox id, If it is not dynamic

http://jsfiddle.net/xjn3Q/65/[^]
 
Share this answer
 
Comments
murkalkiran 12-Sep-14 3:56am    
Sorry Gihan Liyanage its check-box are generated dynamically
You should give each checkbox a property relating to its shortcountrycode. For instance:
HTML
<input type="checkbox" name="country" value="1" data-code="USD"></input>


Then set an event handler with jQuery for any box that's checked:
$(function() {
  $(document).on('change', '[name=country]', function() {
    if ($(this).is(':checked')) {
      var shortcode = $(this).data('code');

      $('input:checkbox[data-code=' + shortcode + ']').prop('checked', true);
    }
  });
});


Writing the event handler this way creates a delegated event handler, able to handle dynamically-created elements.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900