Link to home
Start Free TrialLog in
Avatar of BrianJC67
BrianJC67

asked on

Submit checkbox parameters to .asp page

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

Avatar of BrianJC67
BrianJC67

ASKER

Thanks in advance btw !
Avatar of b0lsc0tt
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
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");
   }


///////////
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
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
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

ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.