Thursday, November 29, 2007

Notes/Web JS to get text from aliased combobox/dialog list

Something I needed today. Thought i could share it with you. Easy to make, but sometimes one forgets that Notes supports JS.

>>Flash-demo
I forgot to refresh, so the alias doesn't show :)

The reason I didn't use "Refresh field on keyword change" is that it's awful on web (reloads the page).

The alias of the combobox/dialog list was the corresponding number to the text (One|1, etc).

>>Demo-application

In Notes, the code also works with hidden/computed fields. For computed fields, set value = @ThisValue.

For the web, you should probably set the text-field to editable, "HTML Attributes" -> "type=\"hidden\"".

In Notes, onChange fires when the field looses focus/value has changed. On the web, the event fires when you select another value.

JS-header - Common Javascript:

function textFromMultivalue( multival, valuefield ){
var f = document.forms[0];
/*if valuefield is the name of the value-field,
get field from form */
var valuefield = ( typeof valuefield == 'string' ) ?
f[valuefield] :
valuefield;
/*if multival is the name of the multival-field,
get field from form */
var multival = ( typeof multival == 'string' ) ?
f[multival] :
multival;

valuefield.value = multival.options[
multival.selectedIndex ].text;
}

onChange in multi-value field (also Common Javascript):
textFromMultivalue( this, 'name_of_textfield' );

0 comments: