If/Then Logic

Is there a way to have a User Input Checkbox field affect another field’s value when the Submit button is clicked on a Dynamic Page?

I’m creating an inventory of items. The Dynamic Page displays one inventory item. On that inventory item page, one field is “Quantity” and another “Picked”. When unckecking the Picked field, I’d like to have the Quantity field default back to “0” when Submitted. Is that possible?

Yes, you can do that with this : wix-dataset - Velo API Reference - Wix.com

Thank you Giri. Looks like I’ll be learning something new tonight! This will be my first real dive into Wix Coding.

Just re-read your question. There is also another way: you could write a small function on the checkbox.onChange event. In that function, you could write an IF-statement like “IF NOT checkbox.checked THEN quantity.value = 0” (This is pseudo code!).
THen the user immediately sees that this happens before submitting.

Actually Giri, that “pseudo code” may be more desirable for instant feedback in this case. Thank you again! Don’t laugh, but I just picked up the book, Coding with JavaScript for Dummies. Hopefully, in a few weeks, I’ll graduate from “Dummy” to “Dangerous”!

Well after a couple weeks, I’m still more Dummy than Dangerous, but with the help of Giri’s suggestion, a JavaScript for Dummies book, Wix Code API Reference, Webix Desgns by Nayeli on YouTube, w3schools and a lot of trial and error, I got this to work!

My page is a Dynamic page showing the detail of one order item. The page has a Quantity ordered (“#qtyinput”) field and a Picked (“#checkbox1”) field.

  1. Once the ordered item is picked from stock, the Picked (“#checkbox1”) is checked.
  2. When the order is packed, the Quantity ordered (“#qtyinput”) field is entered as 0 (zero).

Now the page automatically unchecks the Picked checkbox whenever the Quantity ordered = 0

Here is the code that did it for me:

$w.onReady( () => {

$w("#dynamicDataset").onReady( () => {          // Allow dataset to load 

	$w("#qtyinput").onChange( () => {  		// Monitor Qty (#qtyinput) field for a change in value 
		 
	var itemQty = $w("#qtyinput").value;  	// Declare var itemQty = to "#qtyinput" field value 

		if (itemQty < 1) {				// If "#qtyinput" (Qty) field is 0, do the next line 
		
			$w("#checkbox1").checked = false;	     // Set "#checkbox1" field to unchecked 
	  		$w("#dynamicDataset").setFieldValue("pickUp", false);      // Update Collection 
		} 

	});  
	
});	 

}); // end

P.S. It boggles my mind, what WIX has accomplished with its website building environment. Thanks to everyone at WIX for your hard work and dedication.

Good to see you are willing to study and thus make progress. Hat tip.