• Resolved hsntgm

    (@hsntgm)


    Hello,

    I have checkbox (fieldname234) and when user tick it i want to assign values to my input fields.

    I set up default value of checkbox FALSE in plugin and added this html script to change it TRUE if clicked. This is working.

    
    <script>
    jQuery(document).on(
    'change', 
    '[id*="fieldname'+'234_"]', function(){
    jQuery(this).val(this.checked ? "TRUE" : "FALSE");
    });
    </script>
    

    Then if this value TRUE assign some values to my input fields doesn’t working. (code is below).

    <script>
    jQuery(document).on(
    'click', 
    '[id*="fieldname'+'234_"]', function(){
    	var value = jQuery(this).val();
    	if (value == 'TRUE')
    		{
                jQuery('[id*="fieldname'+'84_"]').val(jQuery('[id*="fieldname'+'13_"]')).change();
            }
            else
            {
                jQuery('[id*="fieldname'+'84_"]').val('').change();
            }
    });
    </script>

    Thanks.

    • This topic was modified 7 years, 10 months ago by hsntgm.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    The correct would be:

    jQuery('[id*="fieldname84_"]').val(jQuery('[id*="fieldname13_"]').val()).change();

    Because in your code you are entering as the value of the fieldname84 field, the fieldname13 field directly, and not its value.

    Best regards.

    Thread Starter hsntgm

    (@hsntgm)

    Hello,

    You are right.

    Also I want to add;

    Code working with this definition;

    
    var value = jQuery('[id*="fieldname234_"]').val();
    

    Not working with this definition;

    
    var value = jQuery(this).val();
    

    And condition must be FALSE because my code isn’t perfect. ?? Maybe i have to declare document ready function but i couldn’t managed to do it.

    Working condition;

    
    if (value == 'FALSE')
    

    Anyway thanks god it is working with these complete code. Maybe helps someone.

    Change the value of checkbox when clicked.

    
    <script>
    jQuery(document).on(
    'change', 
    '[id*="fieldname'+'234_"]', function(){
    jQuery(this).val(this.checked ? "TRUE" : "FALSE");
    });
    </script>
    

    If checkbox clicked, assign values to other input fields.

    <script>
    jQuery(document).on(
    'click', 
    '[id*="fieldname234_"]', function(){
    	var value = jQuery('[id*="fieldname234_"]').val();
    	if (value == 'FALSE')
    	{
                jQuery('[id*="fieldname84_"],[id*="fieldname69_"],[id*="fieldname78_"],[id*="fieldname74_"],[id*="fieldname88_"],[id*="fieldname97_"],[id*="fieldname100_"],[id*="fieldname103_"],[id*="fieldname106_"]').val(jQuery('[id*="fieldname13_"]').val()).change();
            }
            else
            {
                jQuery('[id*="fieldname84_"],[id*="fieldname69_"],[id*="fieldname78_"],[id*="fieldname74_"],[id*="fieldname88_"],[id*="fieldname97_"],[id*="fieldname100_"],[id*="fieldname103_"],[id*="fieldname106_"]').val('').change();
            }
    });
    </script>

    Thanks.

    PS: I will pay you because i am learning JQuery ??

    • This reply was modified 7 years, 10 months ago by hsntgm.
    • This reply was modified 7 years, 10 months ago by hsntgm.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘When clicked checkbox assign values to input field.’ is closed to new replies.