A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Needs a Checkbox script for a contact form

  1. #1
    Member
    Join Date
    Jul 2009
    Posts
    34

    Needs a Checkbox script for a contact form

    Hi guys,

    I am converting an html form to a flash form. I am not so good with AS3 and it's the first time I have to create forms so it was quite difficult for me. I am almost done, I did the text fields and the comboboxes, so everything except the checkboxes works. I don't find any specific tutorial that really explain me how to script it to work like the html form does. I am sure it's quite simple for an advance AS3 user, so please help me with this. Please try to work with what I already did to be sure I can incorporate the new script with what I did.

    Here's the html code for the 5 checkboxes;

    ...<input type="checkbox" name="txtMessage" value="Find Your Pace">...
    ...<input type="checkbox" name="txtMessage" value="Stress Escape">...
    ...<input type="checkbox" name="txtMessage" value="Time Revolution">...
    ...<input type="checkbox" name="txtMessage" value="Ultimate Connections">...
    ...<input type="checkbox" name="txtMessage" value="Contact Me About Life Coaching">...

    Here's an example of how my flash form works;

    var variables:URLVariables = new URLVariables();
    var varSend:URLRequest = new URLRequest("website");
    var varLoader:URLLoader = new URLLoader;
    varSend.method = URLRequestMethod.POST;
    varSend.data = variables;

    submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);

    function ValidateAndSend (event:MouseEvent):void {

    if(!txtfirst.length) {
    status_txt.text = "* Please enter your first name";
    } else {

    variables.txtContactFirstName = txtfirst.text;

    varLoader.load(varSend);
    }

    Thanks guys !

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    If you open the components panel (window > components) you can drag premade checkboxes onto the stage - you should be able to give those an instance name and then test whether they are checked or not with myCheckbox.selected.
    Please use [php] or [code] tags, and mark your threads resolved 8)

  3. #3
    Member
    Join Date
    Jul 2009
    Posts
    34
    Thanks for the reply, but I would need a specific script. I know how to put the checkbox on the stage but I don't know how to write the good script to send the data like the html script I wrote.

  4. #4
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Ahh - you can just jam them into your URLVariables object:

    PHP Code:
    variables.txtContactFirstName txtfirst.text;
    variables.findYourPace checkbox1.selected;
    variables.stressEscape checkbox2.selected;
    //  ... 
    Please use [php] or [code] tags, and mark your threads resolved 8)

  5. #5
    Member
    Join Date
    Jul 2009
    Posts
    34
    Thanks for your help again... I really need to do it a certain way since the database cannot be change at this point. The way it works right now, the variable would be the same for the 5 checkbox, it would be txtMessage, but it could have 5 values total and the values are specific words like value="Find Your Pace"> So I think it should be something like;

    variables.txtMessage = "???";

    How do I give a different text value to each checkbox and how do I cumulate all the values checked to answer the "???".

    Am I clear enough ?

    Thanks

  6. #6
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    I guess I'm not sure how you want these to concatenate together...this sounds more like a radiobutton?

    Anyhow - you can use if..then logic to look through each checkbox:

    PHP Code:
    if(checkbox1.selectedvariables.txtMessage 'Find Your Pace';
    if(
    checkbox2.selectedvariables.txtMessage 'Stress Escape';
    //  ... 
    Or you could combine these into one big string or something (again - not sure how these are supposed to work if more than one is selected):

    PHP Code:
    variables.txtMessage '';
    if(
    checkbox1.selectedvariables.txtMessage += 'Find Your Pace, ';
    if(
    checkbox2.selectedvariables.txtMessage += 'Stress Escape, ';
    //  ... 
    Please use [php] or [code] tags, and mark your threads resolved 8)

  7. #7
    Member
    Join Date
    Jul 2009
    Posts
    34
    Great the second script is working, thanks a lot for your help ! By the way, I had another small issue that I would like to correct. Do you know how to reset a combobox ? After the user submit the form all the information needs to go. I found how to do it for the field text and the checkboxes but not how to reset the combobox.

    txtfirst.text = "";
    workshop1_box.selected = false;

    combobox = ???


    Thanks in advance !!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center