I have a database with a web front end. The database has a form with a dialog list that allows multiple selections. I would like to store these selections in a target field on the form.
In the OnFocus event of the target field, I’ve added the following JavaScript:
var choices = window.document.forms[0].DialogListChoices;
for (index = 0; index<choices.length; index++)
{
if (choices.options[index].selected)
{
this.value = this.value + choices.options[index].text + ", ";
}
}
I have two questions:
1.) The above code is not storing the selected values in the target field as intended. I’d appreciate any suggestions on how the code might be modified.
2.) The form is displayed by a view action. The intent is to pass the target field value to all selected documents in the view. I suspect that one option would be to pass the target field value to a profile doc where it could be accessed by the selected documents. I’d appreciate any other suggestions.
Thanks.
Thanks.
Subject: Multiple Selections in a Dialog List
-
put the code in the onChange of your dialog list, not in the onFocus of your target field.
-
Not sure what you mean by this. You’re in a view, click an action button, and this form opens. Does it open in a popup or new window? If not, how do you expect to “apply to selected documents in the view” when the view goes away as soon as the form is opened?
If the form opens in a new window or popup, look into the window.opener property. You could pass your values to a field on your $$ViewTemplate, and the user could then click a button to apply to all the selected documents.
You might also want to have a look at this article on Codestore that deals with multiple document selection on the web:
http://www.codestore.info/store.nsf/unid/EPSD-5GMT3B?OpenDocument
Subject: RE: Multiple Selections in a Dialog List
I believe what you’re suggesting is to add the following to the onChange event of the Dialog List:
var choices = window.document.forms[0].DialogListChoices;
for (index=0; index<choices.length; index++)
{
if (choices.options[index].selected)
{
window.document.forms[0].TargetField.value = this.value + choices.options[index].text + ", ";
}
}
This still results in an error though. If you have any other ideas, please let me know.
Thanks.
Subject: RE: Multiple Selections in a Dialog List
What is the error you’re getting? What browser are you using?
Subject: RE: Multiple Selections in a Dialog List
When I click on a choice in the Dialog Box, a message appears in the bottom left corner of the pop-up which says ‘Error on page’.
The browser I’m using is IE 6.0.2800.1106.
The pop-up with the Dialog Box is launched by a view action with the following JavaScript in the onClick event:
var url = ‘//<database.nsf/formname?OpenForm’
parentWin=window.open(url,‘Title’, ‘menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes, copyhistory=no,width=375,height=375,left=375,top=5’);
parentWin.opener=self;
Thanks.
Subject: RE: Multiple Selections in a Dialog List
I would strongly suggest doing at least your testing in Mozilla/FireFox/Netscape, even if you have to develop for IE. You’ll get much better error messages - when you suspect an error, type javascript: in the URL bar and you’ll get a console window with all the JavaScript errors that have occurred. In FireFox at least, if you click on one it will open the page source with the error-causing line highlighted.
Subject: RE: Multiple Selections in a Dialog List
The following gives the intended results:
var index;
var choices = window.document.forms[0].Choices;
var selections = window.document.forms[0].Selected;
selections.value = “”;
for (index=0; index<choices.length; index++)
{
if (choices.options[index].selected)
{
selections.value += choices.options[index].text + "\r";
}
}
Thanks Esther.