Page 1 of 1
[SOLVED] How do I put the chosen item of a combo box or list box into a variable?
Posted: Fri Jul 20, 2018 1:55 am
by karmacomposer
I have a combo box (drop down list) with US states and I need to put that into a variable.
In another button, I need to do something with that same variable.
I did the following:
Code: Select all
on menuPick pChosenItem, pPreviousTab
global varState
put pChosenItem into varState
--answer varState with "ok"
end menuPick
That does seem to work (the commented out answer box would show me the correct picked state), but when I try to do something with that same variable when pressing a button, the answer box just shows the word varState, not the contents of the variable varState.
I tried:
Code: Select all
put the text of varState into varStateNew
that did not work and threw an error.
How can I get the value of varState into another control's script?
Mike
Re: How do I put the chosen item of a combo box or list box into a variable?
Posted: Fri Jul 20, 2018 4:28 am
by ClipArtGuy
This script is working as-is here. Make sure you've declared the global in the script you are using it in. Globals need to be declared in every script that uses them. if undeclared, it will be created as an empty local variable on the fly.
Re: How do I put the chosen item of a combo box or list box into a variable?
Posted: Fri Jul 20, 2018 4:38 am
by ClipArtGuy
I think one thing that is messing you up, is using "the text". From this example, you used this :
Code: Select all
put the text of varState into varStateNew
but what you'd want is this:
Same thing for the auto populate example. You used :
Code: Select all
set the text of field "fldDateAllottStart" to varNowDate
when what you should use is:
Code: Select all
put varNowDate into "fldDateAllottStart"
Re: How do I put the chosen item of a combo box or list box into a variable?
Posted: Fri Jul 20, 2018 4:42 am
by karmacomposer
OK, I got it working, but one last problem.
I would like to write the result back to the control.
I wrote this:
Code: Select all
set the text of field "fldState" to it
However, it's a combobox (dropdown list) - how do I write the variable varState back to the control so it shows? Do I use the label command to change the label of cbState?
How would I auto-populate the list back with the 50 states - because when you change the label of the dropdown, you empty the list of states.
Mike
Re: How do I put the chosen item of a combo box or list box into a variable?
Posted: Fri Jul 20, 2018 4:44 am
by ClipArtGuy
again, "the text" is what is wrong here. This is what you want:
Although, here, the combo box shows the choice that has been selected without any need to write back to the control.
Re: How do I put the chosen item of a combo box or list box into a variable?
Posted: Fri Jul 20, 2018 4:48 am
by karmacomposer
That threw an error in the compiler.
The control is a drop down list - not a field.
In fact, I was wrong - the field name is cbState
Still throws an error when I changed it to the correct name.
Mike
Re: How do I put the chosen item of a combo box or list box into a variable?
Posted: Fri Jul 20, 2018 4:54 am
by ClipArtGuy
I was just pointing out that using "set the text" when you should be using "put" is going to cause you headaches every time.
As far as the dropdown menu, you need to change the label:
Code: Select all
set the label of btn "myDropdownMenu" to "myNewLabel"
Re: How do I put the chosen item of a combo box or list box into a variable?
Posted: Fri Jul 20, 2018 5:04 am
by karmacomposer
Thank you. That did it!
Before I mark this solved, is there a way to auto find a state in the list if the user types a set of letters,
for example, without even dropping down the list, I press 'F' and Florida comes up. How would I do this?
Also, does LiveCode have a auto-complete feature such that if you typed something before in a field, it would auto populate with that information?
Thanks.
Mike
Re: How do I put the chosen item of a combo box or list box into a variable?
Posted: Fri Jul 20, 2018 5:06 am
by ClipArtGuy
When it comes to autocomplete in your fields and menus, I think you'll need to roll your own. I am sure someone will chime in if that's not correct