• Resolved hsntgm

    (@hsntgm)


    Hello codepeople !

    I have multiple functions and i forced them to give me their results.Now i will compare these function’s returns by another function.My code structer will tell my problem better then me.

    Unfortunately this structure doesn’t work.
    Thanks in advance.

    
    <script>
    jQuery(document).on(
    'click',
    '[id*="fieldname'+'X_"]', function() MyFunction {
    	var success = false;
    	
    	if (condition) {
    		do something;
                    success = true;
    	
    	} else {
    		do something;
    		success = false;
    	}
    	return success;
    });
    </script>
    
    
    <script>
    jQuery(document).on(
    'click',
    '[id*="fieldname'+'X_"]', function() MySecondFunction {
    	var success = false;
    	
    	if (condition) {
    		do something;
    	        success = true;
    	
    	} else {
    		do something;
    		success = false;
    	}
    	return success;
    });
    </script>
    
    
    <script>
    jQuery(document).on(
    'click',
    '[id*="fieldname'+'X_"]', function() testMyFunctionsAndTakeAction {
    	
    	if (MyFunction() == true && MySecondFunction() == false ) {
    		do something;
    	} 
    });
    </script>
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    There some basic javascript errors, I recommend you the use of a tutorial.

    In javascript if you are defining the functions directly into the event they are lambda functions and do not include a name (furthermore replace the X by the real number in the field’s name, and the pseudo code):

    jQuery(document).on(
    'click',
    '[id*="fieldname'+'X_"]', function(){
    	var success = false;
    	
    	if (condition) {
    		do something;
                    success = true;
    	
    	} else {
    		do something;
    		success = false;
    	}
    	return success;
    });

    If you want to use the function in the event, and call it from another function, the correct is create the function, and then use it in the event:

    function MyFunction(){
    	var success = false;
    	
    	if (condition) {
    		do something;
                    success = true;
    	
    	} else {
    		do something;
    		success = false;
    	}
    	return success;
    }
    
    jQuery(document).on(
    'click',
    '[id*="fieldname'+'X_"]', 
    MyFunction
    );

    Best regards.

    Thread Starter hsntgm

    (@hsntgm)

    Hello,

    Thank you for your patience, i understand lambda functions from tutorials.

    Sometimes my brain looking for more complicated solution.Then i will realise and find the correct path.I managed to solve this issue with simple else if .

    I had to separate the button notifications because of the terms and conditions tickbox unchecked or there are the missing informations.

    So far, so good ! Now all client side validations working like a charm with your support.

    Sincerely,

    Plugin Author codepeople

    (@codepeople)

    Perfect.

    Best regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Testing multiple functions by another function’ is closed to new replies.