Expand my Community achievements bar.

how to get dropdown selected value

Avatar

Former Community Member

I'm trying to set up a form so that a text field will populate with dropdown value.

to bind dropdown i am using sqlserver database.

i tried this but it is not working :-

var sNewSel = this.boundItem(xfa.event.newText);

and

var sNewSel = $.boundItem(xfa.event.newText);

this code works if drop down bind eith XML source but does not work if dropdown bind with sqlserver data base

Please help.. Thanks in advance

7 Replies

Avatar

Level 7

Hi,

Some of your scripting is using "$" which only works in Formcalc

You haven't mentioned which events you're using. In order to get the rawValue of the dropdown box, use the "exit" event of the dropdown box.

     var sNewSel = this.rawValue;       //Javascript  --  you can't use "$" in Javascript, use "this"

     var sNewSel = $                           //FormCalc

To get the text displayed in the dropdown box, use the "change" event of the dropdown box with the xfa.event.newText  (a SOM reference is not used in this)

     var sNewSel = xfa.event.newText;  //Javascript

     var sNewSel = xfa.event.newText     //FormCalc    

Finally, you have some choices to populate the text field--I normally use the change event with xfa.event.newText (this even works if you "Allow Custom Text Entry" in the Field Tab)

     var sNewSel = xfa.event.newText;  //Javascript

     textField.rawValue = sNewSel;

//or 

     var sNewSel = xfa.event.newText     //FormCalc    

     textField = sNewSel

Finally, boundItem, gets the rawValue of a dropdownbox item based on the text that is associated with that rawValue--regardless of what is displayed in the dropdownbox. In other words, it looks at the whole list of items the dropdown can display, and returns the boundItem (meaning, the rawValue) of the item wanted based on the text. So,if

$.clearItems()

$.addItem(one,1)

$.addItem(two,2)

$.addItem(three,3)

var sNewSel = $.boundItem("two")   //returns: 2    so, sNewSel now has a value of 2

                                                          //regardless of what is displayed (if anything)

Good luck!

Stephen

PS, be careful not to mix formCalc and javaScript in the same script like using

$ vs this 

and .rawValue is needed in javaScript, but not formCalc.

Avatar

Former Community Member

Thanks for the help.....

I tried this But 

this.rawValue returning wrong value for e.g.

1. select text from dropdown - for first time it returns null

2.second time select from dropdown - it returns firrstime selected value

i had tried this "$.boundItem(xfa.event.newText)" in formCalc on dropdown change event doesnot work when dropdown bounded from sqlserver database.

Please suggest....

Avatar

Level 7

Hi,

I really don't quite understand what it is you want to accomplish. For dropdown boxes, there are pairs of values as in $.addItem("whatYouSee","rawValue").

The

$.boundItem(xfa.event.newText) will work on the "change" event of the dropdown box and return "rawValue" .   //but why use a script like this?

Instead, use on the "exit" event 

     $                               //formCalc

//or

     this.rawValue.           //javaScript

//either one of these returns the "rawValue"

////////////////////////////////////////////////////////

      $.boundItem(xfa.event.newText)        //on the "change" event FormCalc

     this.boundItem(xfa.event.newText);     //on the "change" event

returns the exact same thing as

     $                                                       //on the "exit" event FormCalc

     this.rawValue                                   //on the "exit" event Javascript

////////////////////////////////////////////////////

You seem to be making this harder than it really is.

Perhaps, I don't understand what it is you are trying to accomplish.

Stephen

Message was edited by: kingphysh

Avatar

Former Community Member

     $                                                       //on the "exit" event FormCalc

     this.rawValue                                   //on the "exit" event Javascript

it works but in this returns wrong value

e.g --

Display value= site1 , raw value =1

Display value= site2 , raw value =2

Display value= site3 , raw value =3

 

TextField1=$;

step 1 :- run the form select site1 return null ------here it should fill text box with 1

step:-2 select site2 it returns 2  null ------here it should fill text box with 2

Avatar

Level 7

OK, if you want to fill TextField1 you need to be aware of scripting language (formCalc vs javascript) and the event ("exit", "change", someotherEvent?)

Since I don't know what you are using, it is not possible to troubleshoot your problem.

What Language?

What Event?

Stephen

Avatar

Former Community Member

thank you very much...it fixed.

i was writing script on change event it needs to be written on exit event.