Solved

How to set a variable to a checkbox?

Posted on 2004-08-27
49
159 Views
Last Modified: 2010-04-03
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
0
Comment
Question by:isotherm
  • 26
  • 22
49 Comments
 
LVL 3

Expert Comment

by:mixart
ID: 11928551
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
 

Author Comment

by:isotherm
ID: 11929060
Thanks Mixart - I will try this morning....will post back here whether successful!
cheers
Jim
0
 

Author Comment

by:isotherm
ID: 11929155
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
 
LVL 10

Expert Comment

by:muso120999
ID: 11929668
Have you checked that "chk1" is actually set a value after the submit button is pressed?
ie. trace("Checked value: "+chk1);
0
 

Author Comment

by:isotherm
ID: 11929711
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
 
LVL 10

Expert Comment

by:muso120999
ID: 11930058
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
 
LVL 10

Expert Comment

by:muso120999
ID: 11930083
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
 

Author Comment

by:isotherm
ID: 11930109
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
 

Author Comment

by:isotherm
ID: 11930161
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
 
LVL 10

Expert Comment

by:muso120999
ID: 11930813
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
 

Author Comment

by:isotherm
ID: 11932901
Nope - same thing - constantly 'false'...:-(
0
 
LVL 10

Expert Comment

by:muso120999
ID: 11936171
is chk1 the name of your checkbox?
0
 

Author Comment

by:isotherm
ID: 11936578
yep. I have three actually, chk1, chk2, chk3

0
 
LVL 10

Expert Comment

by:muso120999
ID: 11936727
Hmm...  selected works for me.

Try putting this code in one of yourCheckBoxes

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

Does it alternate true/false?
0
 

Author Comment

by:isotherm
ID: 11936795
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
 
LVL 10

Expert Comment

by:muso120999
ID: 11936818
Which checkbox component are you using - is it the standard MM one?

Are you using Flash 5?
0
 

Author Comment

by:isotherm
ID: 11936824
Yep - standard one - Flash MX
0
 

Author Comment

by:isotherm
ID: 11936839
I'm assuming this code
box1 = (chk1.selected==true) ? "true" : "false";

is placed in the frame? Not on the checkbox itself?
0
 
LVL 10

Expert Comment

by:muso120999
ID: 11936938
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
 
LVL 10

Expert Comment

by:muso120999
ID: 11936977
> 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
 

Author Comment

by:isotherm
ID: 11937038
Sorry - I don't get where that '_root.' would go - is it before the 'trace' function is called?

thanks for your patience!
0
 
LVL 10

Expert Comment

by:muso120999
ID: 11937089
Try:
box1 = (_root.chk1.selected==true) ? "true" : "false";

and for the trace:
onClipEvent(mouseUp){
     trace(_root.chk1.selected);
}
0
 

Author Comment

by:isotherm
ID: 11937237
:-(
nope - still just returns 'undefined'....
0
 

Author Comment

by:isotherm
ID: 11937321
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 10

Expert Comment

by:muso120999
ID: 11937337
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
 

Author Comment

by:isotherm
ID: 11937378
Thanks Muso - but I'm still getting 'undefined' here..I just don't understand it!
0
 
LVL 10

Accepted Solution

by:
muso120999 earned 250 total points
ID: 11937396
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
 

Author Comment

by:isotherm
ID: 11937424
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
 
LVL 10

Expert Comment

by:muso120999
ID: 11937444
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
 

Author Comment

by:isotherm
ID: 11937478
Ah - I see. So when passed to the ASP it will be the right way round..

:0)
0
 
LVL 10

Expert Comment

by:muso120999
ID: 11939579
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
 

Author Comment

by:isotherm
ID: 11939596
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
 
LVL 10

Expert Comment

by:muso120999
ID: 11939706
> 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
 

Author Comment

by:isotherm
ID: 11939933
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
 
LVL 10

Expert Comment

by:muso120999
ID: 11940161
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
 

Author Comment

by:isotherm
ID: 11940230
Yikes - fear does encourage you to pick things up quick!
0
 

Author Comment

by:isotherm
ID: 11947556
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
 

Author Comment

by:isotherm
ID: 11947573
..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
 
LVL 10

Expert Comment

by:muso120999
ID: 11947629
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
 

Author Comment

by:isotherm
ID: 11947823
Nope - still blank - ( have removed redundant code!)

:0(
0
 
LVL 10

Expert Comment

by:muso120999
ID: 11947842
Are they actually blank, or always false again?
0
 
LVL 10

Expert Comment

by:muso120999
ID: 11949914
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
 

Author Comment

by:isotherm
ID: 11950024
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
 
LVL 10

Expert Comment

by:muso120999
ID: 11950051
Anywhere really - at the end will do.  It literally should just dump the contents of the form data
0
 

Author Comment

by:isotherm
ID: 11950197
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
 
LVL 10

Expert Comment

by:muso120999
ID: 11950224
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
 

Author Comment

by:isotherm
ID: 11950342
It works!!!
Yaay!
Thanks muso - fantastic stuff... :-))
0
 
LVL 10

Expert Comment

by:muso120999
ID: 11950347
Yipee!

Was that cstr that worked?
0
 

Author Comment

by:isotherm
ID: 11950390
Yep! Guess  it was
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now