Manage Learn to apply best practices and optimize your operations.

Select a value in a dialoglist and then check (in onchange event)

Select a value in a dialoglist and then check (in onchange event) if a certain field in the document of the selected value.

Select a value in a dialoglist and then check (in onchange event) if a certain field in the document of the selected value, for example 'status', is OK.
Example:
PROBLEM

A first dialoglist with the product ID's of a productcatalogue : DialogList1 Code: (use formula for choices)

Existing := @DbLookup("";"":""; "ProductView"; keyvalue ; 4 );
Products := @If(@IsError(Existing) ; ""; "":Existing);
Products;

When the user selects a product (ID) we want to check immediately if the status of that product is not 'Sold Out', and if necessary, give an alert back.

The problem is, we can't access the server side to retrieve the status with javascript!

SOLUTION:
We create a second dialoglist (DialogList2) with exact the same formula (accessing the same view), but with another column retrieved:

Code:

Existing := @DbLookup("";"":""; "ProductView"; keyvalue ; 5 );
Status := @If(@IsError(Existing) ; ""; "":Existing);
Status;

Attention! This dialoglist should not be seen by users, but when you hide it, javascript doesn't recognize it anymore as being a dialoglist.

There is a little workaround for this : put in the HTML Attributes of the field: "style=" width:0;"" Now this field is also hidden and we can keep on using it by javascript !

So we have exact the same number of values in the two dialoglists (because they have the same dblookup formula, except the columnnr retrieved). No we can use the selectedindex of the first dialoglist to retrieve the corresponding value in the second dialoglist

Code: Code (ONCHANGE event of the first dialoglist) :

i = document.forms[0]. DialogList1.selectedIndex;

//Check if the second dialoglist exists
if ( document.forms[0]. DialogList2 != null  ) {
	var StatusValue = document.forms[0]. DialogList2.options[i].text;
	if (   StatusValue == "Sold Out"   ) {
		alert('Attention ! The product is sold out' )
	}
}
 

Dig Deeper on Domino Resources - Part 5

SearchWindowsServer
Search400
  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/Search400.com community. These cheat ...

SearchDataCenter
SearchContentManagement
Close