Notes Ninjas Notes Ninjas
Lotus Notes hints, tips, error messages
MasterClass: Allow user to choose value other than keyword choices

Hint Short Cut: Add this to your code & documentation to help you find this page.
http://www.notesninjas.com/#JSOther or http://www.notesninjas.com/A555F9/nn.nsf/ByAlias/JSOther


If you have a keyword in Notes and tick the allow other values box the field becomes a text box instead of a pick list or a dialog list on the web browser. This code shows how to make an "Other" button which solves the problem.





How it works

This javascript code presents to the user a button. The button, takes a new value from the user and then sets the pulldown value to be that value. Simple.

The added benefit is that the button can be hidden from certain users, to allow only "Power Users" to be able to add new categories for example.

REM "This code allows another value to be specified on a pull down field on the web browser.";
REM "This code should be placed in a Computed Text element with Pass-Thru HTML ticked";
REM "Replace Name with the name of the keyword field with 'Allow other values' NOT ticked.";
REM "Code is from http://www.NotesNinjas.com/#JSOther";

REM "If not edit mode then do nothing";
@if( @isdocbeingedited=0;@return("");"");


"<input type=\'button\' value=\'Other\' onclick=\"val = prompt(\'Enter New Value:\', \'\'); if(val==\'\' || val==null) {alert(\'Enter a value!\'); return false;} else { "+
"var categoryfield = window.document.forms[0].Name;"+
"var newindex = categoryfield.length;"+
"categoryfield.length = newindex + 1;"+
"categoryfield.options[newindex].text = val;"+
"categoryfield.value = val;"+
"categoryfield.options[newindex].selected = true;}"+
" return false;\">"

 

One problem with this code has been found:

If you have refresh fields on keyword change and you have already selected a 'Other' value the form's fields will be reset to default values. This is because Notes R5.07 and above has changed how the server deals with forms that have had their field's choices changed. The form is now reloaded.

Very annoying. So don't use "refresh fields on keyword change" on any fields on any forms using this code.

 

 Jump to:     Notes Tips
    Lotus Notes Index 
  Register for Tips
Previous Lotus Notes Tip 
    Next Lotus Notes Tip
Your company logo here?
Adam Foster
Free Cash Making Web Site
Free Revenue Earning Blog Site
 Free Revenue Earning Newsletter Site   
Free Search Pages Free Web stats
Free Contact Us page
Cheap .com domain names
 Need a website or 
   Lotus Notes
  problem solved?
Adam Foster
Web Services Platform Architecture: Soap, WSDL, WS-Policy, WS-Addressing, WS-Bpel, WS-Reliable Messaging and More by Francisco Curbera, Frank Leymann, Tony Storey, Donald Ferguson, Sanjiva Weerawarana
Other books claim to present the complete Web services platform architecture, but this is the first one I've seen that really does. The authors have been intimately involved in the creation of the architecture. Who better to write this book?
See at: Amazon.co.uk | Amazon.com |