[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Submit checkbox parameters to .asp page

Posted on 2008-02-04
9
Medium Priority
?
822 Views
Last Modified: 2012-06-27
I have 5 checkboxes inside a movieclip, each representing a sub section of an e-learning module. The user cherrypicks the sections they want to view and submits the info to a server. I found some code that enabled me to pass the label name of each selected box in the form of an array to the .asp page. (Current code included)

My developer however has asked me to pass checkbox ID's to the .asp page instead of the checkbox label name, eg,  
moduleID=1 subsection=1, moduleID=1 subsection=2,  etc. (<----probably bad syntax). I know how to pass name value pairs to an .asp page, I now need to pass multiple pairs via checkboxes, into an array and submit this to an asp page.




/

current code
 
///code on movieclip///
   onClipEvent(load)
   {
      _global.checkboxArray = new Array();
   
      _global.testIfSelected = function (t) 
      {
         for(i=0;i<checkboxArray.length;i++)
         {
            if(checkboxArray[i]==t)
            {
               return i;
            }
         }
         return -1;
      }
   }
 
///code on every checkbox///
on (click) {
      var pos=testIfSelected(this.label);
   
      if(this.selected == true)
      {      
         if(pos == -1) checkboxArray.push(this.label);
      } 
      else 
      {
         if(pos >=0) checkboxArray.splice(pos,1);
      }
   }
 
/
 
///code on submit button///
 
on (release)
   {      
      var selectedCheckboxes=checkboxArray.join(",");
         
      sendData = new LoadVars();
   
      sendData.checkboxes= selectedCheckboxes;
   
      sendData.send("http://localhost/filename.asp","_blank","GET");
   }

Open in new window

0
Comment
Question by:BrianJC67
  • 4
  • 4
9 Comments
 

Author Comment

by:BrianJC67
ID: 20817190
Thanks in advance btw !
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20819997
BrianJC67,

I am not a Flash expert (I know the ASP part) but what about just using the Query string.  For example your url would be ...

http://localhost/filename.asp?check1=value1&check2=value2 ...

That is a common way to do what you want.  If Flash can make cookies then it may also be an option.  If Flash can create the Post part of the header (i.e. manufacturer the form post) then that could also work.  I can't help with those details though.

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 20820712
Hi BrainJC67,

we can't send arrays, objects as querystring whether use GET or POST.
data can be send only as string variables,

but you can send multiple varaibles using same code, below is the example to expand your code more more variables:

//////////
on (release)
   {      
      var selectedCheckboxes=checkboxArray.join(",");
         
      sendData = new LoadVars();
   
      sendData.checkboxes= selectedCheckboxes;
      sendData.anotherVariable= "somevlaue";
      sendData.var3= "var3value";
      sendData.fourthVar= "varvalue";
      //similarly you can add more variables to send back to ASP

      sendData.send("http://localhost/filename.asp","_blank","GET");
   }


///////////
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:BrianJC67
ID: 20823308
If I understand right, these are just new variables to send to the asp page right?

 What I really need is some sort of listener which tells the .asp page which checkboxes were clicked, in the form of a string of ID's for each clicked checkbox. eg if I check boxes 2 and 4 I want to send this info to the asp page: checkbox= M1S2, M1S4 etc

Hope I'm making sense
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20829373
Are you looking for script for the ASP page or the Flash movie or both?  Mentioning a listener has confused this for me.  When is the ASP page called?

If the code you have is passing the label and you need the id then how about ...

///code on every checkbox///
on (click) {
      var pos=testIfSelected(this.label);
   
      if(this.selected == true)
      {      
         if(pos == -1) checkboxArray.push(this.id);
      }
      else
      {
         if(pos >=0) checkboxArray.splice(pos,1);
      }
   }
 
/

With the on release code suggested above this should pass the field's id (if I am reading the script, etc right).

bol
0
 

Author Comment

by:BrianJC67
ID: 20830673
Thanks for that bol, I should have been more specific. My Developer is taking care of the asp end, I was just worrried about passing the right kind of parameter to his script. This is a great soloution & very simple, thanks. To answer your question the asp is called on a button release (see below).


I have one more problem though. When the parameters are passed via a url, they are all in this format:
http://localhost/filename.asp?checkboxes=1%2C2%2C3   whereas I really need the parameters to be checkboxes=1,2,3. Do you know of any way to encode this in actionscript so that a clean string is sent to the asp?

Many thanks again

on (release)
   {      
      var selectedCheckboxes=checkboxArray.join(",");
         
      sendData = new LoadVars();
   
      sendData.checkboxes= selectedCheckboxes;
	
   
      sendData.send("http://localhost/filename.asp","_blank","POST");
   }

Open in new window

0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 2000 total points
ID: 20833535
You don't want to "fix" that.  The comma character is reserved in the URL so you can't use it as a literal character in the URL.  Instead it needs to encoded.  In the case of a comma that is %2C.

This should not be an issue though.  The ASP script can unencode it.  I have seen cases where a specific character can be hard to unencode but then you just use a different character.  Check with the developer and he may choose to have you use something instead of the comma which will not be URL unsafe or reserved.

Let me know if you have a question about this.

bol
0
 

Author Comment

by:BrianJC67
ID: 20834007
Thanks again,

on the character subject, would you know where this is defined by looking at my code??
I guess this is a worry for another day however.

Cheers
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20834747
Your welcome!  I'm glad I could help.

>> would you know where this is defined by looking at my code?? <<

If you are asking about where the comma is defined then that is in the line with the join I believe.  You could just replace the comma in that line with some URL safe character.  If you do have more questions about that and post a new question for it then feel free to post that question's URL here to get out attention.

Thanks for the grade, the points and the fun question.

bol

p.s.  It seems to me the other expert helped too.  If that is the case then a split would've been appropriate.  Let us know about this.  If you meant to do that then let me know and I can reopen this.  I might be wrong about what did answer this but wanted to point this out in case you meant to or should've split.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

611 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