This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Update Text Field Type from Dropdown Selection

MMarcial - Friday, March 23, 2007 1:39 PM:

Can someone provide example code (VB prefered) that shows how to update text field types on a form based on a dropdown control?

My dropdown control is fed from a List.  Based on what the user selects in the dropdown I want to append the List Lable to a text1 and update text2 with List  Value.



RobMcAveney - Friday, March 23, 2007 2:45 PM:

I'm not sure I completely understand the request.  Is this purely a UI thing, or do you actually want to change values in the database based on the List selection?


snnicky - Saturday, March 24, 2007 4:17 PM:

If I understand the question correctly and you want to run some VB code on a form when drop down selection is changed. Then the following may be a possible solution.

Let's assume you have an ItemType Q205 with 2 properties mylist and mystr. Also you have a Innovator Form Q205 with 2 fields mylist and mystr on that.

A couple of notes.
Standard Innovator client runs under IE (Internet Explorer). IE natively supports VBScript and JScript script languages.

However Innovator supports JScript only as Method client side language.


I'll provide two samples (run steps as Innovator administrative user):
1. JScript Method:
 a) edit Q205 Form;
 b) select MyList field in a fields list;
 c) choose "Field Event" tab;
 d) pick "Create Related" in a dropdown and click "new relationship";
 e) specify some name for the newly created Method (e.g. q205_demo), set Method Type=JavaScript, event=onChange;
 f) click "view item" on toolbar (this will open Method editor);
 g) input the following JScript :
 
var val = window.event.srcElement.value;
if (window.handleItemChange) window.handleItemChange(/* property name */ "mystr", /* property value */ val);
 

 h) close the Method window;
 i) save the Q205 form;
 j) Done. Open an instance of Q205 ItemType and test the Form.


2) VBScript code:
 a) - f) the same as above;
 g) input the following JScript :
 
if (typeof(q205_vbscript_demo) !== "undefined") q205_vbscript_demo(); /* call VBScript function */
 

 h) close the Method window;
 i) create a new HTML field and input the following html there:
 
<script type="text/vbscript">
Function q205_vbscript_demo()
  Dim val
  val = window.event.srcElement.value
 
  If Not window.handleItemChange Is Nothing Then window.handleItemChange "mystr", val
End Function
</script>

 j) save the Form;
 k) Done.
 >


So if you prefer VBScript you may add such code directly to a Form and call that from a short JScript method.
On my opinion this makes sense only if you have to write a big piece of code and don't want to waste time studing JScript.
However in such case you get more tricky code.

In both samples UI is refreshed and the modifications will be saved if end-user saves an item.

To get label for the selected option you may use:

'VBScript sample to get selected item label from a dropdown MsgBox window.event.srcElement.item(window.event.srcElement.selectedIndex).text