Dynamically loading data into the drop down box

I have a UI componant (combo box) and I want to be able to load the list from a text file.
Is this possible? If so, how?
The other thing I need is to be able to send the selection from the combo box into a mysql database. I have set up a php page that sends the data from my text boxes to the database, so really all I need is to know how to send it to php.
I hope this makes sense, if not I'll try and explain better. Just let me know.

Cheers

-OBCT
LVL 9
OBCTAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

negatyveCommented:
Create a "combodata.xml" xml file, and write in it:

<?xml version="1.0" encoding="UTF-8"?>
<combodata>
      <item label="First Label"      data="first" />
      <item label="Second Label"      data="second" />
      <item label="Third Label"      data="third" />
      <item label="Fourth Label"      data="fourth" />
      <item label="Fifth Label"      data="fifth" />
      <item label="Sixth Label"      data="sixth" />
</combodata>

then, in your movie, call your combobox, for example, "combo_cb", and drop this code on the same frame:

combo_cb.setEnabled(false);
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.path = this;
data_xml.onLoad = function(ok)
{
      this.path.combo_cb.setEnabled(true);
      if(ok){
            var nodes = this.firstChild.childNodes;
            for(var i = 0; i < nodes.length; i++){
                  this.path.combo_cb.addItem(nodes[i].attributes.label, nodes[i].attributes.data);
            }
            this.path.combo_cb.setChangeHandler("changeData");
            this.path.changeData(combo_cb);
      } else {
            this.path.combo_cb.addItem("no data found");
            this.path.combo_cb.setEnabled(false);
      }
};
function changeData(_cb)
{
      this.yourVariable = _cb.getSelectedItem().data;
}
data_xml.load("combodata.xml");



with this code, when you change the selected item, the "yourVariable" variable is created in the same timeline where the combo lies, holding the selected item data.
If you want to create it in a loadVars instance, change the code to:

data_var = new LoadVars();

combo_cb.setEnabled(false);
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.path = this;
data_xml.onLoad = function(ok)
{
      this.path.combo_cb.setEnabled(true);
      if(ok){
            var nodes = this.firstChild.childNodes;
            for(var i = 0; i < nodes.length; i++){
                  this.path.combo_cb.addItem(nodes[i].attributes.label, nodes[i].attributes.data);
            }
            this.path.combo_cb.setChangeHandler("changeData");
            this.path.changeData(combo_cb);
      } else {
            this.path.combo_cb.addItem("no data found");
            this.path.combo_cb.setEnabled(false);
      }
};
function changeData(_cb)
{
      data_var.yourVariable = _cb.getSelectedItem().data;
}
data_xml.load("combodata.xml");


Now, when you send you data to php (you know how, if you send data from textfields), you get that variable with:

$_POST['yourVariable']
0
OBCTAuthor Commented:
Ok I've done that and its working fine.
I just have to more questions....

1) How can I adjust the width of the combo box?

2) I was intending on using LoadVars to send the data to my php page seeing the rest of my data is sent that way, but....
how to I get flash to get the variable the user has selected?  e.g. a text box uses      newVars.txt_1 = txt_1.text       so what would/should I use for the combo box?

Cheers

-OBCT
0
rascalpantsCommented:
your combo box will automatically adjust to the max item size...  so you don't have to worry about that...

you can use loadvars if you want...

you would just send that information in the changeData function above....  like this:

function changeData(_cb)
{
    myData = new LoadVars();
    myData.yourVariable = _cb.getSelectedItem().data;
    myData.sendAndLoad("/yourpage.php", myData, "POST");
    myData.onLoad = function(success){
        if(success){
           trace("successful transaction");
        } else {
           trace("an error occured in the transaction");
        }
    };
}


I believe, that is all you need...  then you would collect the "yourVariable"  using the method posted above by Negatyve....


hope that helps to clarify...


rp
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

OBCTAuthor Commented:
I tried adding the loadvars in my on release function, but now I'm having three problems.
1) The username and email are not being submited to my db anymore
2) The combo box didn't adjust its width automatically
3) In the database, in the column that contains my variable from the combo box, it says undefiend.

What did I do wrong??
0
OBCTAuthor Commented:
Sorry about those errors, they were my own little errors which I have fixed up now.
However, in my database I am still getting "undefiend" in the column that is meant to hold the value from my text box.
0
negatyveCommented:
it should be:

$_POST['textfield_associated_variable']
0
OBCTAuthor Commented:
This is the code I am using, and it wont send anything into my database. The way I had it working before was using loadVariablesNum with the GET method...
any suggestions?

combo_cb.setEnabled(false);
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.path = this;
data_xml.onLoad = function(ok)
{
     this.path.combo_cb.setEnabled(true);
     if(ok){
          var nodes = this.firstChild.childNodes;
          for(var i = 0; i < nodes.length; i++){
               this.path.combo_cb.addItem(nodes[i].attributes.label, nodes[i].attributes.data);
          }
          this.path.combo_cb.setChangeHandler("changeData");
          this.path.changeData(combo_cb);
     } else {
          this.path.combo_cb.addItem("no data found");
          this.path.combo_cb.setEnabled(false);
     }
};
function changeData(_cb)
{
     this.newUser = _cb.getSelectedItem().data;
}
data_xml.load("http://www.dfgsgsdfgsdfg.com/xml/combodata.xml");

submitBTN.onRelease = function() {
      if (!username.length) {
            status = "Please enter a username"
      } else {
            if (!email.length or email.indexOf("@") == -1 or email.indexOf(".") == -1 or email.indexOf("com") == -1) {
                  status = "Please enter a valid email"
            } else {
                  if (email.length < 7) {
                        status = "Please enter a valid email"
                  } else {
                        status = "Loading...Please wait..."
                        var newUser = new LoadVars()
                        newUser.username = _root.username
                        newUser.email = _root.email
                        newUser.timeZone = _root._cb.getSelectedItem().data
                        newUser.load("http://www.dfgsfgsdfg.com/scripts/register.php", 0, "POST")
                        newUser.onLoad = function(success) {
                              if (success) {
                                    status = "Complete"
                              } else {
                                    status = "Error"
                              }
                        }
                  }
            }
      }
}
0
OBCTAuthor Commented:
Can someone please help!
0
negatyveCommented:
try it:

combo_cb.setEnabled(false);
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.path = this;
data_xml.onLoad = function(ok)
{
      this.path.combo_cb.setEnabled(true);
      if (ok) {
            var nodes = this.firstChild.childNodes;
            for (var i = 0; i < nodes.length; i++) {
                  this.path.combo_cb.addItem(nodes[i].attributes.label, nodes[i].attributes.data);
            }
            this.path.combo_cb.setChangeHandler("changeData");
            this.path.changeData(combo_cb);
      } else {
            this.path.combo_cb.addItem("no data found");
            this.path.combo_cb.setEnabled(false);
      }
};
function changeData(_cb)
{
      this.newUser = _cb.getSelectedItem().data;
}
data_xml.load("http://www.dfgsgsdfgsdfg.com/xml/combodata.xml");
submitBTN.onRelease = function()
{
      if (!this._parent.username.length) {
            this._parent.status = "Please enter a username";
      } else {
            if (!this._parent.email.length ||
                  this._parent.email.indexOf("@") == -1 ||
                  this._parent.email.indexOf(".") == -1 ||
                  this._parent.email.indexOf("com") == -1) {
                  this._parent.status = "Please enter a valid email";
            } else {
                  if (this._parent.email.length < 7) {
                        this._parent.status = "Please enter a valid email";
                  } else {
                        this._parent.status = "Loading...Please wait...";
                        this._parent.newUser = new LoadVars();
                        this._parent.newUser.path = this._parent;
                        this._parent.newUser.username = this._parent.username;
                        this._parent.newUser.email = this._parent.email;
                        this._parent.newUser.timeZone = this._parent.combo_cb.getSelectedItem().data;
                        this._parent.newUser.onLoad = function(success)
                        {
                              if (success) {
                                    this.path.status = "Complete";
                              } else {
                                    this.path.status = "Error";
                              }
                        };
                        this._parent.newUser.sendAndLoad("http://www.dfgsfgsdfg.com/scripts/register.php", this._parent.newUser, "POST");
                  }
            }
      }
};
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OBCTAuthor Commented:
I tried that, used $HTTP_POST_VARS on my php script and it didn't add anything into the database.
0
OBCTAuthor Commented:
I know there isn't anything wrong with my php page because when I try something like this:
http://www.sdlfhs.com/scripts/register.php?username=Blah&email=i_live@themoon.com
it enters it into the db.
0
OBCTAuthor Commented:
LOL sorry my bad. I forgot to save my php script after I changed everything to HTTP_POST_VARS.
Thanks for all your help, you really are an expert!

Cheers!

-OBCT
0
negatyveCommented:
yeah!! :)

cheers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.