When we use a lookup to populate a drop down it fills but replaces the list of choices in the drop down with only the matched lookup item. No longer can the user select the default list of drop down choices. We want to use the lookup to put a default choice in but allow the user to override the lookup and select from the original list. Alternatively, we considered using a radio button instead but don't seem to be able to fill that from a lookup. How can we accomplish this?
Question
Question
How to use a database lookup to only select a default choice in a drop down list
Answer
Hi Jeremy,
To add default values to a lookup, I've place the default values into the database view. If you're using an older version of Forms, you could wait a couple of seconds then add your defaults to the drop down. In Forms 10, there is a call back when a lookup has completed... It's a bit messy (to clarify, I'm more comfortable with SQL than with JavaScript) so I prefer to just add the defaults to the database view/lookup with the "union all" command in SQL view's definition.
as in...
create view formsLookup as select forename, surname, staffID from staflist union all select 'defaut name1', 'default surname 1', 'default id1' union all select 'defaut name2', 'default surname 2', 'default id2'
As for populating the radio button, I've had similar issues. Eventually my solution was to have the lookup populate a hidden text field and use javascript to set the radio button based on the value of the hidden text field.
Hey thanks Ben! I appreciate your super speedy answer. Could you give me a sample of the javascript to fill a radio button that way? I'm pretty sure we can figure it out once we have the basic idea.
This javascript will run after a database lookup populates a text field. The value in the text field is then used to set a radio button. Finally, the radio button is triggered to activate a field rule.
$('.myText input').change( function() { $('.myRadio input').val([$('.myText input').val()]); $('.myRadio input').change(); });
I'm just getting started with Javascript and Forms. When you use .myRadio in the above, is that because you have set the CSS Class for the field to myRadio? Could you be using the #q7 type reference format instead?
Hi Clarence. yes and yes