<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic If function when checkBox is checked and unchecked in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/If-function-when-checkBox-is-checked-and-unchecked/m-p/738594#M92003</link>
    <description>&lt;PRE&gt;&lt;FONT face="Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//Define Function1&lt;BR /&gt;Function1 = Function( {},
    // Code for function 1 goes here
    Print("Checkbox is checked! Function 1 executed.");
);

// Define function 2
Function2 = Function( {},
    // Code for function 2 goes here
    Print("Checkbox is unchecked! Function 2 executed.");
);

// Create a new window
nw = New Window( "Checkbox Example",
    &amp;lt;&amp;lt; Modal,
    // Add a checkbox to the window
    cb = Checkbox( "Toggle Function", Value( 0 ) )
);

// Add an OK button to the window
nw &amp;lt;&amp;lt; Append( Button Box( "OK", 
    // Function to execute when OK button is clicked
    &amp;lt;&amp;lt;Set Function( 
        Function( {this},
            If( cb &amp;lt;&amp;lt; Get Selected(),
                Function1(); // Call function 1 if checkbox is checked
            ,
                Function2(); // Call function 2 if checkbox is unchecked
            );
            // Close the window after execution
            Close( this );
        )
    )
));&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face="Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace" color="#000000"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;Hi, The code above is similar to what I am trying to do. I have a check box, and if I select it, and then click ok, function 1 should be displayed; and if i do not select it and click ok, function 2 should be displayed.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Mar 2024 14:10:43 GMT</pubDate>
    <dc:creator>GgGgGg2024</dc:creator>
    <dc:date>2024-03-25T14:10:43Z</dc:date>
    <item>
      <title>If function when checkBox is checked and unchecked</title>
      <link>https://community.jmp.com/t5/Discussions/If-function-when-checkBox-is-checked-and-unchecked/m-p/738594#M92003</link>
      <description>&lt;PRE&gt;&lt;FONT face="Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//Define Function1&lt;BR /&gt;Function1 = Function( {},
    // Code for function 1 goes here
    Print("Checkbox is checked! Function 1 executed.");
);

// Define function 2
Function2 = Function( {},
    // Code for function 2 goes here
    Print("Checkbox is unchecked! Function 2 executed.");
);

// Create a new window
nw = New Window( "Checkbox Example",
    &amp;lt;&amp;lt; Modal,
    // Add a checkbox to the window
    cb = Checkbox( "Toggle Function", Value( 0 ) )
);

// Add an OK button to the window
nw &amp;lt;&amp;lt; Append( Button Box( "OK", 
    // Function to execute when OK button is clicked
    &amp;lt;&amp;lt;Set Function( 
        Function( {this},
            If( cb &amp;lt;&amp;lt; Get Selected(),
                Function1(); // Call function 1 if checkbox is checked
            ,
                Function2(); // Call function 2 if checkbox is unchecked
            );
            // Close the window after execution
            Close( this );
        )
    )
));&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face="Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace" color="#000000"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;Hi, The code above is similar to what I am trying to do. I have a check box, and if I select it, and then click ok, function 1 should be displayed; and if i do not select it and click ok, function 2 should be displayed.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2024 14:10:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/If-function-when-checkBox-is-checked-and-unchecked/m-p/738594#M92003</guid>
      <dc:creator>GgGgGg2024</dc:creator>
      <dc:date>2024-03-25T14:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: If function when checkBox is checked and unchecked</title>
      <link>https://community.jmp.com/t5/Discussions/If-function-when-checkBox-is-checked-and-unchecked/m-p/738597#M92004</link>
      <description>&lt;P&gt;That script looks like it has been created by ChatGPT or something similar and it does have few issues. Below is example which should work&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

func1 = function({}, {Default Local},
	Show(1)
);


func2 = function({}, {Default Local},
	Show(2)
);

nw = New Window("",
	window:cb = Check Box({""}),
	Button Box("OK",
		If(window:cb &amp;lt;&amp;lt; get,
			func1()
		,
			func2()
		);
	)
)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Mar 2024 14:28:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/If-function-when-checkBox-is-checked-and-unchecked/m-p/738597#M92004</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-03-25T14:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: If function when checkBox is checked and unchecked</title>
      <link>https://community.jmp.com/t5/Discussions/If-function-when-checkBox-is-checked-and-unchecked/m-p/739067#M92032</link>
      <description>&lt;P&gt;You are absolutely correct.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can i nest a function? (write a function within a function)&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;CheckBoxHandler = Function ({cb},
	If ( cb &amp;lt;&amp;lt; Get,
		//Call function with apple/banana if checkbox is checked	
		checkedbox ()
		,
		//Else
		//Call function with mango/watermelon if checkbox is not checked 
		uncheckedbox ()
	   ),
	);&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//Function 1 - box is checked
checkedbox = Function ({},
	Match ( x, 
			"a", callapple,  
			"b", callbanana
		)
);

//Function 2 - box is not checked
uncheckedbox = Function ({},
	Match (x, 
			"a", callmango,  
			"b", callwatermelon	
		)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need to add a match function in the [ Button Box ("OK",&amp;nbsp; ] command&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2024 08:23:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/If-function-when-checkBox-is-checked-and-unchecked/m-p/739067#M92032</guid>
      <dc:creator>GgGgGg2024</dc:creator>
      <dc:date>2024-03-26T08:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: If function when checkBox is checked and unchecked</title>
      <link>https://community.jmp.com/t5/Discussions/If-function-when-checkBox-is-checked-and-unchecked/m-p/739073#M92034</link>
      <description>&lt;P&gt;Very easy to test by just trying it&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

a = function({}, {Default Local},
	Show("a");
);

b = function({}, {Default Local},
	Show("b");
);

func1 = function({input_value = 1}, {Default Local},
	Match(input_value,
		1, a(),
		2, b()
	);
);


func2 = function({}, {Default Local},
	Show(2)
);

func3 = function({}, {Default Local},
	If(window:cb &amp;lt;&amp;lt; get,
		func1()
	,
		func2()
	);	
);

nw = New Window("",
	window:cb = Check Box({""}),
	Button Box("OK",
		func3();
	)
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would start testing something like this without the check box and new window as those just add extra layer of complexity. You have to first be able to solve how functions work together before you start adding them to check boxes and so on.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2024 08:53:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/If-function-when-checkBox-is-checked-and-unchecked/m-p/739073#M92034</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-03-26T08:53:38Z</dc:date>
    </item>
  </channel>
</rss>

