How to set a variable to a checkbox?

Arrrrgggggghhhhhhhhhhhh!!
Thats better.

I wonder if someone could explain to me how on earth you set about giving a checkbox in a form a varibale.

I'm passing the form to a CDONTS ASP page, and I have three checkboxes, which I need to appear in the retuened email as either blank or 'checked'.

Can anyone assist?

thanks
Jim
isothermAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
muso120999Connect With a Mentor Commented:
I'm testing the file with ActionScript 1, and Flash 6 as in MX, so it should be the same:

This is in chk1 (on the checkbox itself):
onClipEvent(mouseUp){
      trace(this);
      trace(_root.chk1.getValue());
}

Toggling the checkbox, I get this
_level0.chk1
false
_level0.chk1
true

No problem!!
0
 
mixartCommented:
Look under your flash help for getSelectedItem() for info...

U should give the checkbox an instance name. Then where you have all your variables to send to your .asp along with name, adress ect. you should put
instance = instance.getSelectedItem().label;

instance being the instancename you gave your checkbox.

Hope that helps
0
 
isothermAuthor Commented:
Thanks Mixart - I will try this morning....will post back here whether successful!
cheers
Jim
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
isothermAuthor Commented:
No - not working :-(

My chk box is called 'chk1'

So my AS on my submit button looks like this:
on (release) {
      chk1 = chk1.getSelectedItem().label;
getURL("http://www.holmes.7host.com/promise/mypage.asp", "", "POST");

}

My corresponding ASP page looks like this:

<% @language="VBSCRIPT" %>
<%

Dim myMail, myBody

myBody = "Name: "& request.form("name") & vbcrlf
myBody = myBody & "Email: "& request.form("email") & vbcrlf
myBody = myBody & "Position: "& request.form("position") & vbcrlf
myBody = myBody & "Company: "& request.form("company") & vbcrlf
myBody = myBody & "Address: "& request.form("address") & vbcrlf
myBody = myBody & "Postcode: "& request.form("postcode") & vbcrlf
myBody = myBody & "Telephone: "& request.form("telephone") & vbcrlf
myBody = myBody & "Open Courses: "& request.form("chk1") & vbcrlf
myBody = myBody & "In house Courses: "& request.form("chk2") & vbcrlf
myBody = myBody & "Organisational Development: "& request.form("chk3") & vbcrlf
myBody = myBody & "Message: "& vbcrlf & request.form("message")

Set myMail = CreateObject("CDONTS.NewMail")

myMail.BodyFormat=1
myMail.MailFormat=1
myMail.From=request.form("email")
myMail.To="holmes@dircon.co.uk"
myMail.Subject="Response from Promise Website"
myMail.Body=myBody
myMail.Send

set myMail=nothing

%>

I get all the info, but nothing for the checkboxes???

Any other ideas where I'm going wrong?

thanks v much!
0
 
muso120999Commented:
Have you checked that "chk1" is actually set a value after the submit button is pressed?
ie. trace("Checked value: "+chk1);
0
 
isothermAuthor Commented:
Good point muso - no - it seems no value is being set. ( why didn't I think of that!)
So - why is no value being set * sigh* :-)
0
 
muso120999Commented:
Have you tried something like:
chk1 = (chk1.getValue()==true) ? "true" : "false";

This is of course assuming that chk1.getValue() is returning a value though.  I haven't checked how a boolean translates when it gets posted with your method, which is why I suggest maybe trying assigning it a string value - as above.  Be careful that this doesn't always return "false" if there is still a problem returning the value from the checkbox.
0
 
muso120999Commented:
Actually, I think the assignment is flawed anyway:
chek1 = (chk1.getValue()==true) ? "true" : "false";

chk1 shouldn't overwrite the Checkbox instance, so assign a variable with a different name to it
0
 
isothermAuthor Commented:
Thanks Muso - but which part of that statement is tthe variable?

chk1 = (chk1.getValue()==true) ? "true" : "false";

chk1 =

Is this bit the declared variable? So if I changed it to:

box1 = (chk1.getValue()==true) ? "true" : "false";

that would be better?
0
 
isothermAuthor Commented:
I think we are getting somewhere - though you are correct - it does always return 'false' - but at least it's returning something. How do I reslove the permanent 'false' value being set?

thanks
Jim
0
 
muso120999Commented:
Sorry, it seems getValue and getSelectedItem aren't supported by the CheckBox component; selected is.

And, yes, I would change it to "box1 = " (that is the variable, as it is what is being assigned the
value).

Try this:
box1 = (chk1.selected==true) ? "true" : "false";

0
 
isothermAuthor Commented:
Nope - same thing - constantly 'false'...:-(
0
 
muso120999Commented:
is chk1 the name of your checkbox?
0
 
isothermAuthor Commented:
yep. I have three actually, chk1, chk2, chk3

0
 
muso120999Commented:
Hmm...  selected works for me.

Try putting this code in one of yourCheckBoxes

on(click){
      trace(this.selected);
}

Does it alternate true/false?
0
 
isothermAuthor Commented:
No - for a start it tells me it has to be on a clip event - but the trace just throws up 'undefined' whether checked ot not....
0
 
muso120999Commented:
Which checkbox component are you using - is it the standard MM one?

Are you using Flash 5?
0
 
isothermAuthor Commented:
Yep - standard one - Flash MX
0
 
isothermAuthor Commented:
I'm assuming this code
box1 = (chk1.selected==true) ? "true" : "false";

is placed in the frame? Not on the checkbox itself?
0
 
muso120999Commented:
I think the differences are because you are using Flash MX - I'm on MX2004.

There is a little bit of info here, and it appears you need the FULL path to the CheckBox in MX for it to read the value...
http://livedocs.macromedia.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=00002128.html

Does this help?
0
 
muso120999Commented:
> is placed in the frame? Not on the checkbox itself?

Sorry, that's correct...  although it would work equally well on the onClipEvent(mouseUp) I think
0
 
isothermAuthor Commented:
Sorry - I don't get where that '_root.' would go - is it before the 'trace' function is called?

thanks for your patience!
0
 
muso120999Commented:
Try:
box1 = (_root.chk1.selected==true) ? "true" : "false";

and for the trace:
onClipEvent(mouseUp){
     trace(_root.chk1.selected);
}
0
 
isothermAuthor Commented:
:-(
nope - still just returns 'undefined'....
0
 
isothermAuthor Commented:
I have posted the .fla here if you want to take a look - it's not very big:

http://www.holmes.7host.com/promise_4.fla

:0)


0
 
muso120999Commented:
Okay,

I just tried this, and it works
      trace(_level0.chk1.getValue());

Looks like it was maybe "selected" after all that caused a problem?

Nice looking project!
0
 
isothermAuthor Commented:
Thanks Muso - but I'm still getting 'undefined' here..I just don't understand it!
0
 
isothermAuthor Commented:
Hey! It works! It's back to front ( so when checked it reads as false - but who cares!)...thats great - now all I have to do is figure how to read this into the ASP page that handles the form.

Thanks so much for your efforts Muso!
0
 
muso120999Commented:
Hey, I'm just glad we got there in the end!!

Yes, it doesn't get set a value until after you press it, so it's true value is always NOT what is being traced.  It would be correct where you originally had the code though.
0
 
isothermAuthor Commented:
Ah - I see. So when passed to the ASP it will be the right way round..

:0)
0
 
muso120999Commented:
The only reason that it is the wrong way around, is because the code is on the mouseUp function; it seems that this is triggered before the onChange of the CheckBox.  In any case, if it is still the wrong way around, you can just reverse it's value when setting the value of the variable to go to the form ;-)
0
 
isothermAuthor Commented:
Yep! Thats great.

Are you familiar with ASP? Just wondering the correct way to call the chkbox variables given the way the rest of the form data is retrieved ( see code at top of page) - or should I start a new question?

Thanks Muso!
0
 
muso120999Commented:
> Are you familiar with ASP?

ASP VBScript - grudgingly, yes! (I don't like VBScript much personally)

> the correct way to call the chkbox variables given the way the rest of the form data is retrieved

Exactly the same way as the other variables; if you use:
box1 = (_root.chk1.getValue()==true) ? "true" : "false";

as before it will ensure that the value passed is a string, and is true/false.  That just makes it easier to read, if you email the results, but you can equally set the strings to "-1" and "0", for a database for example
0
 
isothermAuthor Commented:
Cool - thanks muso.
Did you do a course in this stuff or just teach yourself?
Trouble is I'm a designer really and as such have a brain that struggles with logic and math!
0
 
muso120999Commented:
Taught myself.  I've been programming in various languages for a long time, and read a book on advanced actionscript from cover-to-cover (forget what it was called) before I even started.  I had been thrown in at the deep-end at work though, as my first project was an all Flash/HTML app integrated with ASP, and to be used by about 5,000 users.  Mind, with that kind of pressure, you learn fast!
0
 
isothermAuthor Commented:
Yikes - fear does encourage you to pick things up quick!
0
 
isothermAuthor Commented:
Arrrgh! Just when yo think you have won - I can't get the values into the asp form > and email response now!

using:
myBody = myBody & "Open Courses: "& request.form("box1") & vbcrlf
myBody = myBody & "In house Courses: "& request.form("box2") & vbcrlf
myBody = myBody & "Organisational Development: "& request.form("box3") & vbcrlf

but just come in blank :-(
0
 
isothermAuthor Commented:
..and these actions on the submit button:
on (release) {
      box1 = chk1.getSelectedItem().label;
      box2 = chk2.getSelectedItem().label;
      box3 = chk2.getSelectedItem().label;
      box1 = (_root.chk1.getValue()==true) ? "true" : "false";
      box2 = (_root.chk2.getValue()==true) ? "true" : "false";
      box3 = (_root.chk3.getValue()==true) ? "true" : "false";
      
getURL("http://www.holmes.7host.com/promise/mypage.asp", "", "POST");
}
0
 
muso120999Commented:
try:
    _root.box1 = (_root.chk1.getValue()==true) ? "true" : "false";
     _root.box2 = (_root.chk2.getValue()==true) ? "true" : "false";
     _root.box3 = (_root.chk3.getValue()==true) ? "true" : "false";

btw, the three proceeding lines are redundant in your code, as the values are re-assigned by these three lines.
0
 
isothermAuthor Commented:
Nope - still blank - ( have removed redundant code!)

:0(
0
 
muso120999Commented:
Are they actually blank, or always false again?
0
 
muso120999Commented:
You could maybe use this ASP code to see what information is actually being passed to it, it might give a clue:

<%
Response.Write(Request.Form)
%>

I still dont get how box1/2/3 are not being sent with the POST data, as I think it should be all the fields in _root.  getURL posts data from whereever it is called - i.e. myMovieClip.getURL( ... ) would submit all fields in the movieclip object myMovieClip.

I hope this is helping!
0
 
isothermAuthor Commented:
Hi muso - yep the fields are blank - not false..
and yes, this is helping a lot thanks!

Whereabouts do i put the 'response.write'...at the end of the asp page?
0
 
muso120999Commented:
Anywhere really - at the end will do.  It literally should just dump the contents of the form data
0
 
isothermAuthor Commented:
FUIComponentClass=%5Btype+Function%5D&FCheckBoxClass=%5Btype+Function%5D&FPushButtonClass=%5Btype+Function%5D&box1=true&box2=false&box3=false&message=test&name=jim&position=ghj&company=ghjgh&address=jg&postcode=hjghj&telephone=ghj&email=ghjghjghj
 

well - seems to me like thats showing a result for box 1,2,3?

So why doesn't it post in the email?
0
 
muso120999Commented:
Not sure - maybe it's treating it as a boolean

try converting it to a string for myBody:  cstr(request.form("box1"))

or changing true/false to something else:  ? "true" : "false";
0
 
isothermAuthor Commented:
It works!!!
Yaay!
Thanks muso - fantastic stuff... :-))
0
 
muso120999Commented:
Yipee!

Was that cstr that worked?
0
 
isothermAuthor Commented:
Yep! Guess  it was
0
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.

All Courses

From novice to tech pro — start learning today.