PDA

View Full Version : list box component not inserting data


somnamblst
09-05-2007, 03:12 AM
I have a Flash form that writes to an Access DB using an ASP script. It has 5text input fields & 1 Flash list box component which is set to multiple selections and has both the data & label parameters set via parameters panel. All 5 input text fields do successfully write to the DB. The list box component is inserting undefined.

The variable name of the list box is OnlineAdTypes. It has an instance name of myListbox.

Here is the AS on my submit button

function doSubmit()
{
userData = new LoadVars();
var myListbox = OnlineAdTypes;
userData.Name = Name;
userData.Advertiser = Advertiser;
userData.TypeAd = TypeAd;
userData.When = When;
userData.NonAdCustomOnline = NonAdCustomOnline;
userData.OnlineAdTypes = OnlineAdTypes.selectedItem.data
trace(OnlineAdTypes.selectedItem.data)
userData.send
("processForm.asp",0,"post");
gotoAndStop(5);
}
doSubmit();
}


My processForm.asp script

<%@language = "VBScript" %>
<%
strName = Request.Form("Name")
strAdvertiser = Request.Form("Advertiser")
strTypeAd = Request.Form("TypeAd")
strWhen = Request.Form("When")
strOnlineAdTypes = Request.Form("OnlineAdTypes")
strNonAdCustomOnline = Request.Form("NonAdCustomOnline")

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"DBQ=\\content\main_data\sharedDB\onlineAdCounter.m db;"
SQL = "INSERT INTO contacts (Name, Advertiser, TypeAd, When, OnlineAdTypes, NonAdCustomOnline) VALUES ('"&strName&"','"&strAdvertiser&"','"&strTypeAd&"','"&strWhen&"','"&strOnlineAdTypes&"','"&strNonAdCustomOnline&"' )"
conn.Execute SQL, recaffected

Response.Write(strName) & "<br>"
Response.Write(strAdvertiser) & "<br>"
Response.Write(strTypeAd) & "<br>"
Response.Write(strWhen) & "<br>"
Response.Write(strOnlineAdTypes) & "<br>"
Response.Write(strNonAdCustomOnline) & "<BR/><br/>"
Response.Write(recAffected)
%>


The asp script is passing this Response.Write

elton john
benny & the jets
spec
08/27/07
undefined
goodbye

1

I have found lots of examples of DB passing data to the list box component but none for vise versa.

panel
09-05-2007, 07:35 AM
list component has two fields label (what you see) and data (real data), you can send label or make sure data is set correctly.

somnamblst
09-05-2007, 01:22 PM
I also tried

on(press){
function doSubmit()
{
userData = new LoadVars();
var myListbox = OnlineAdTypes;
userData.Name = Name;
userData.Advertiser = Advertiser;
userData.TypeAd = TypeAd;
userData.When = When;
userData.NonAdCustomOnline = NonAdCustomOnline;
userData.OnlineAdTypes = OnlineAdTypes.getSelectedItems().label
userData.send
("processForm.asp",0,"post");
gotoAndStop(5);
}
doSubmit();
}



Looking at some other threads regarding multiple selections, do I need an array to setRecord or insert?

somnamblst
09-06-2007, 02:39 AM
I am attempting to mod the list box array example from this thread
http://www.actionscript.org/forums/showthread.php3?t=24170

Am I in the right ballpark?

function doSubmit()

{

userData = new LoadVars();

var myListbox = OnlineAdTypes;

userData.Name = Name;

userData.Advertiser = Advertiser;

userData.TypeAd = TypeAd;

userData.When = When;

userData.NonAdCustomOnline = NonAdCustomOnline;

userData.OnlineAdTypes = OnlineAdTypes.selectedItem.label

trace(OnlineAdTypes.selectedItem.label)


arr = [];
arr.push({data:1, label:"one"});
arr.push({data:2, label:"two"});
arr.push({data:3, label:"three"});
arr.push({data:4, label:"four"});
arr.push({data:5, label:"five"});
arr.push({data:6, label:"six"});
arr.push({data:7, label:"seven"});
arr.push({data:8, label:"eight"});
arr.push({data:9, label:"nine"});
arr.push({data:10, label:"ten"});
myListBox.setDataProvider(arr);

myListBox.setDataProvider(arr);
myListBox.setChangeHandler("setRecord");

myobj=SharedObject.getLocal("userData");
myTmpIndices = myobj.data.dataArray;
myobj.flush();
if (myTmpIndices.length > 0) {
myListBox.setSelectedIndices(myTmpIndices);
}


function showMe(component) {
myArr = component.getSelectedIndices();
myIndices = [];
for(x in myArr) {
myIndices.push(component.getItemAt(myArr[x]).data);
}
saveData(myIndices);
if (myArr.length>3) {
component.setEnabled(false);
}
}

function insertData(what) {
myobj=SharedObject.getLocal("savedData");
myobj.data.dataArray = what;
myobj.flush();
};

userData.send

("processForm.asp",0,"post");

gotoAndStop(5);

}

doSubmit();

somnamblst
09-08-2007, 03:07 PM
I have been struggling with a Flash form that has a multi-select Flistbox component & 5 text inputs that writes to a DB for some time. Well I just found an example on MacromediaDev for a pizza order form & I modded it to fit my categories. Wondering if there are any obvious mistakes, like am I doing things in the wrong order?

Listbox has an instance name of myListBox, variable name is OnlineAdTypes

on(press){
function onSubmit() {
}

// Initialize form variables:

userData = new LoadVars();
var myListbox = OnlineAdTypes;
userData.Name = "";
userData.Advertiser = "";
userData.TypeAd = "";
userData.When = "";
userData.NonAdCustomOnline = "";



// Get list box selection(s):

// getSelectedItems returns an array of objects with two properties: label

// and data

OnlineAdTypesObjectArray = OnlineAdTypes_lb.getSelectedItems();

for (var i = 0; i < OnlineAdTypesObjectArray.length; i++) {

currentOnlineAdType = OnlineAdTypesObjectArray[i];

formData.OnlineAdTypes[i] = currentOnlineAdType.label;

}

// Submit the data and advance to frame 5

// Change the URL to point to the CFM or ASP file on your

// web server.

userData.send
("processForm.asp",0,"post");
gotoAndStop(5);
}


Here is my processForm.asp


<%@language = "VBScript" %>
<%
strName = Request.Form("Name")
strAdvertiser = Request.Form("Advertiser")
strTypeAd = Request.Form("TypeAd")
strWhen = Request.Form("When")
strOnlineAdTypes = Request.Form("OnlineAdTypes")
strNonAdCustomOnline = Request.Form("NonAdCustomOnline")

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"DBQ=\\content\main_data\sharedDB\onlineAdCounter.m db;"
SQL = "INSERT INTO contacts (Name, Advertiser, TypeAd, When, OnlineAdTypes, NonAdCustomOnline) VALUES ('"&strName&"','"&strAdvertiser&"','"&strTypeAd&"','"&strWhen&"','"&strOnlineAdTypes&"','"&strNonAdCustomOnline&"' )"
conn.Execute SQL, recaffected

Response.Write(strName) & "<br>"
Response.Write(strAdvertiser) & "<br>"
Response.Write(strTypeAd) & "<br>"
Response.Write(strWhen) & "<br>"
Response.Write(strOnlineAdTypes) & "<br>"
Response.Write(strNonAdCustomOnline) & "<BR/><br/>"
Response.Write(recAffected)
%>

somnamblst
09-08-2007, 06:32 PM
So I grabed a snippet of functionVariableTransmission code from yet another listbox thread

function variableTransmission(){
if(packages_lb.getSelectedItems() != undefined){
activities_so.packages_array = packages_lb.getSelectedItems();
}
}

also do I need a changeHandler?

My current code

on(press){
function onSubmit() {
}

// Initialize form variables:

userData = new LoadVars();
var myListbox = OnlineAdTypes;
userData.OnlineAdTypes = OnlineAdTypes;
userData.Name = Name;
userData.Advertiser = Advertiser;
userData.TypeAd = TypeAd;
userData.When = When;
userData.NonAdCustomOnline = NonAdCustomOnline;



// Get list box selection(s):

// getSelectedItems returns an array of objects with two properties: label

// and data

//create array to hold selected items

OnlineAdTypesArray = new Array();

//populate array with selected items
OnlineAdTypesArray = component.getSelectedItems();


for (var i = 0; i < OnlineAdTypesArray.length; i++) {

currentOnlineAdTypes = OnlineAdTypesArray[i];

userData.OnlineAdTypes[i] = currentOnlineAdTypes.label;

}

function variableTransmission(){
if(OnlineAdTypes_myListbox() != undefined){
OnlineAdTypesArray = OnlineAdTypes_myListbox.getSelectedItems();
}
}


// Submit the data and advance to frame 5

// Change the URL to point to the CFM or ASP file on your

// web server.

userData.send
("processForm.asp",0,"post");
gotoAndStop(5);
}

CyanBlue
09-08-2007, 06:45 PM
Howdy and Welcome... :)

I see you are going back and forth with multiple code snippets, but I am really not understanding what your problem is... and I think many others think the same way...

Why don't you try separating your problems???
First of all, you need to know whether you are accesing the data correctly before you put them into the LoadVars object's properties... Are you sure you are getting them correctly???
Try adding these trace() lines right after you define them and show me what you get in the Output panel...
trace("userData.OnlineAdTypes = " + userData.OnlineAdTypes);
trace("userData.Name = " + userData.Name);
trace("userData.Advertiser = " + userData.Advertiser);
trace("userData.TypeAd = " + userData.TypeAd);
trace("userData.When = " + userData.When);
trace("userData.NonAdCustomOnline = " + userData.NonAdCustomOnline);

somnamblst
09-08-2007, 07:05 PM
Thanks CyanBlue!

Here is my trace:

userData.OnlineAdTypes = undefined
userData.Name = paul mccartney
userData.Advertiser = abby road
userData.TypeAd = sold
userData.When = 08/31/01
userData.NonAdCustomOnline = hello

processForm.asp is also doing a Response.Write so I knew that I keep getting undefined

Since I only care about allowing multiple selections & not whether the user interacts with a pulldown list or check boxes, could what I am trying be done with check boxes, and would the data summitted be separated by commas?

CyanBlue
09-08-2007, 07:11 PM
and what's the output from the ASP file??? ;)

somnamblst
09-08-2007, 07:21 PM
well I haven't reuploaded to the server as my VPN connection timed out but it's always the same, undefined and 1 for recAffected

elton john
benny & the jets
spec
08/27/07
undefined
goodbye

1

CyanBlue
09-08-2007, 07:39 PM
What if you say this???
//var myListbox = OnlineAdTypes;
userData.OnlineAdTypes = myListbox.selectedItem.data;
trace("userData.OnlineAdTypes = " + userData.OnlineAdTypes);
What do you see on the Outpua panel and the ASP page???
As for the recAffected, isn't that supposed to be '1' cuz you only had one transaction???

somnamblst
09-08-2007, 07:59 PM
link to FLA: http://archive.cinweekly.com/z/form2.fla

Response.Write

axel rose
sold
Guns N Roses
08/31/07
undefined
hello

1

trace

userData.OnlineAdTypes = undefined
userData.Name = porky pig
userData.Advertiser = loonie tunes
userData.TypeAd = sold
userData.When = 08/31/01
userData.NonAdCustomOnline = goodbye

instance name: myListbox

linkaqe identifier: List

CyanBlue
09-08-2007, 10:51 PM
Replace your code with this...
Mind you that the value of the OnlineAdTypes will be 'value1|value2|value3|', so you'd need to parse it back to however you can use within your ASP code...
on (press)
{
// Initialize form variables:
userData = new LoadVars();
userData.Name = Name;
userData.Advertiser = Advertiser;
userData.TypeAd = TypeAd;
userData.When = When;
userData.OnlineAdTypes = "";
for (var i:Number = 0 ; i < myListbox.selectedItems.length ; i++)
{
userData.OnlineAdTypes += myListbox.selectedItems[i].data + "|";
}
userData.NonAdCustomOnline = NonAdCustomOnline;
//
trace("userData.Name = " + userData.Name);
trace("userData.Advertiser = " + userData.Advertiser);
trace("userData.TypeAd = " + userData.TypeAd);
trace("userData.When = " + userData.When);
trace("userData.OnlineAdTypes = " + userData.OnlineAdTypes);
trace("userData.NonAdCustomOnline = " + userData.NonAdCustomOnline);
//
userData.send("processForm.asp", "_blank", "post");
gotoAndStop(5);
}

somnamblst
09-08-2007, 11:25 PM
Success!

Susan
google
sold
09/08/07
Flash 728x90|Flash 300x250|Flash 120x600|Flash 160x600|Flash 300x250|Flash 300x600|
Mootools SmoothGallery

1

CyanBlue if you don't mind, how come this works?
userData.OnlineAdTypes = "";
for (var i:Number = 0 ; i < myListbox.selectedItems.length ; i++)
{
userData.OnlineAdTypes += myListbox.selectedItems[i].data + "|";

CyanBlue
09-08-2007, 11:33 PM
Well... The ListComponentInstance.selectedItems returns you the selected data in an array format, so I am simply looping through them to prepare the data to send out to the ASP code... ;)

somnamblst
09-09-2007, 01:48 AM
well between Kirupa & Expertsexchange you are the only one who knew what to do.

CyanBlue
09-10-2007, 03:01 PM
Those are two of many communities that I don't have time to go back... :(

None the less, there are many people who know what they are doing... You just need to give them right thoughts to answer you back... ;)