View Full Version : [AS2] Retreive data from checkbox
Magnix
09-30-2008, 06:33 PM
I can't get the data from the checkbox to post on log.txt. It shows blank while other data works OK from txtfields, combobox and radiobox.
myCheckboxListener = new Object();
myCheckboxListener.click = function ()
{
if ( ckYes.selected )
{
formData.varYesProServ = ckYes.getValue("Selected");
}
else
{
formData.varYesProServ = ckYes.getValue("Unselected");
}
Did I do something wrong above code?
Thanks in advance!
xxneon
09-30-2008, 09:16 PM
Flash CheckBox components don't have a method of 'getValue()'
are you just wanting to pass "Selected" or "Unselected" based on where the component is checked or not??
myCheckboxListener.click = function ()
{
if ( ckYes.selected )
{
formData.varYesProServ = "Selected";
}
else
{
formData.varYesProServ = "Unselected";
}
}
or are you wanting to store something different for the form data..
Magnix
09-30-2008, 09:35 PM
Flash CheckBox components don't have a method of 'getValue()'
are you just wanting to pass "Selected" or "Unselected" based on where the component is checked or not??
myCheckboxListener.click = function ()
{
if ( ckYes.selected )
{
formData.varYesProServ = "Selected";
}
else
{
formData.varYesProServ = "Unselected";
}
}
or are you wanting to store something different for the form data..
Yeah, if the checkbox is selected, it should pass the "Selected" and if not then "Unselected" should be passed and display it on log.txt.
Going to try your codes....
Thanks!
Magnix
09-30-2008, 09:41 PM
Yeah, if the checkbox is selected, it should pass the "Selected" and if not then "Unselected" should be passed and display it on log.txt.
Going to try your codes....
Thanks!
Nope, that didnt work.
This is the log.txt Im showing below -
Name: dsfdsf
City: sdfdsf
Email: sdfsdf
State: Alaska
Own Accessory: N
Accessory: WEP210
Handset: BlackBerry
Comment: dsfsdfdsf
Checkbox: <-------------- blank
xxneon
09-30-2008, 09:49 PM
did you add the listener??
ckYes.addEventListener("click",myCheckboxListener);
Magnix
09-30-2008, 09:53 PM
did you add the listener??
ckYes.addEventListener("click",myCheckboxListener);
This is the entire code in order?
ckYes.addEventListener("click",myCheckboxListener);
myCheckboxListener.click = function ()
{
if ( ckYes.selected )
{
formData.varYesProServ = "Selected";
}
else
{
formData.varYesProServ = "Unselected";
}
}
Thanks.
xxneon
09-30-2008, 09:54 PM
do you create the object before you add the listener?
var myCheckboxListener:Object = new Object(); //<~~
ckYes.addEventListener("click",myCheckboxListener);
Magnix
09-30-2008, 10:11 PM
do you create the object before you add the listener?
var myCheckboxListener:Object = new Object(); //<~~
ckYes.addEventListener("click",myCheckboxListener);
var myCheckboxListener:Object = new Object();
ckYes.addEventListener("click",myCheckboxListener);
myCheckboxListener.click = function ()
{
if ( ckYes.selected )
{
formData.varYesProServ = "Selected";
}
else
{
formData.varYesProServ = "Unselected";
}
}
That didnt work. Still shows blank on log.txt. I double checked the var and instance they are all correct.
xxneon
09-30-2008, 10:38 PM
what is the serverside code to get the value from the forData variable that is associated to the checkbox.
Magnix
09-30-2008, 10:44 PM
what is the serverside code to get the value from the forData variable that is associated to the checkbox.
<body>
Name: <%= request("varName") %><br />
City: <%= request("varCity") %><br />
Email: <%= request("varEmail") %><br />
State: <%= request("varState") %><br />
Own Accessory: <%= request("varOwnAccessory") %><br />
Accessory: <%= request("varAccessory") %><br />
Handset: <%= request("varHandset") %><br />
Comment: <%= request("varComment") %><br />
Checkbox: <%= request("varYesProServ") %><br />
<%
if request("varName") <> "" then
WriteToFile()
end if
%>
</body>
</html>
<script runat="server" language="vbscript">
Sub WriteToFile()
dim filename
Dim objFSO, objFile, arrLines
Dim strData
filename = Server.MapPath("log.txt")
Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
Set objFile=objFSO.CreateTextFile(filename)
strData = ""
strData = strData + "Name: " + request("varName") + vbcrlf
strData = strData + "City: " + request("varCity") + vbcrlf
strData = strData + "Email: " + request("varEmail") + vbcrlf
strData = strData + "State: " + request("varState") + vbcrlf
strData = strData + "Own Accessory: " + request("varOwnAccessory") + vbcrlf
strData = strData + "Accessory: " + request("varAccessory") + vbcrlf
strData = strData + "Handset: " + request("varHandset") + vbcrlf
strData = strData + "Comment: " + request("varComment") + vbcrlf
strData = strData + "Checkbox: " + request("varYesProServ") + vbcrlf
objFile.WriteLine(strData)
objFile.Close
Set objFile=Nothing
Set objFSO=Nothing
End Sub
</script>
xxneon
10-01-2008, 03:46 PM
is formData a basic object, loadvars object, movieclip? and is the checkbox located in the same timeline as the rest of the form fields that are tied to formData.. maybe upload a zip of your fla if possible..
Magnix
10-01-2008, 04:09 PM
Here you go...
xxneon
10-01-2008, 04:24 PM
you have the code inside the submit button function that is why its not working .. but take out all the code that you have now for adding the listener and just simply have this in the submit button code.. there is no need for the listener function at all .. cause the submit button can directly check the selected property of the checkbox.. and then assign the value based on whether its selected or not..
so...
replace ..
//...
var myCheckboxListener:Object = new Object();
ckYes.addEventListener("click",myCheckboxListener);
myCheckboxListener.click = function ()
{
if ( ckYes.selected )
{
formData.varYesProServ = "Selected";
}
else
{
formData.varYesProServ = "Unselected";
}
with this..
//...
if ( ckYes.selected )
{
formData.varYesProServ = "Selected";
}
else
{
formData.varYesProServ = "Unselected";
}
and it should work.
Magnix
10-01-2008, 05:02 PM
Can you please send me the FLA with your changes for me to see what you did, because on the log.txt it showed "Selected", but the rest of the above showed "undefined".
Thanks very much!
Magnix
10-01-2008, 05:50 PM
This is what I have in the submit button -
on(release){
if ( ckYes.selected )
{
formData.varYesProServ = "Selected";
}
else
{
formData.varYesProServ = "Unselected";
}
var msgRec = new LoadVars();
var formData = new LoadVars();
formData.varName = txtName.text;
formData.varCity = txtCity.text;
formData.varEmail = txtEmail.text;
formData.varState = stateCBFlash.getValue();
formData.varOwnAccessory = accGroup.getValue();
formData.varAccessory = accessoryCB.getValue();
formData.varHandset = handsetCB.getValue();
formData.varComment = txtComment.text;
formData.sendAndLoad("contactus.asp", msgRec, "POST");
gotoAndStop(3);
}
The log.txt shows -
Name: undefined
City: undefined
Email: undefined
State: undefined
Own Accessory: undefined
Accessory: undefined
Handset: undefined
Comment: undefined
Checkbox: Selected
zavior
10-27-2009, 04:46 AM
Greetings
I was just following a conversation that you were having, explaining the use of the checkbox.
I have tried to apply your ideas, but I keep coming up with the error that this all needs to be on an "on or onclip event"
I am trying to get the checkbox to load a movie when checked and unload a movie when unchecked....
Here is what I have:
the instance name of the component is bldg
var myCheckboxListener:Object = new Object();
bldg.addEventListener("click",myCheckboxListener);
myCheckboxListener.click = function ()
{
if ( bldg.selected )
{
loadMovie("FRANCIS_GABLES_bldgs.swf",1);
}
else
{
unloadMovie("FRANCIS_GABLES_bldgs.swf",1);
}
}
thanx for your help!!
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.