A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [F8] Submitting a form with enter

  1. #1
    Junior Member
    Join Date
    Feb 2007
    Posts
    6

    [F8] Submitting a form with enter

    I created a Flash form that calls up a php script. Everything works fine with it but there is one thing I'd like to add. Right now you can enter info in the fields and click the submit button or tab to the submit button and press return to submit.

    I really want people to be able to press return from the second field (there are only two fields) and submit WITHOUT having to tab over. My flash code looks like this:

    butsubmit.onPress = function(){
    requestForm.name = name_txt.text;
    requestForm.email = email_txt.text;

    requestForm.send("requestForm.php","_blank","POST" );

    name_txt.text = "";
    name_email.text = "";
    }

    var requestForm:LoadVars = new LoadVars();

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    Code:
    keyWatch = new Object();
    Key.addListener(keyWatch);
    
    keyWatch.onKeyDown = function(){
    if(Key.getCode() == Key.ENTER){
    // your submit code
    }
    };
    Test in swf or browser, if testing in authoring mode - Disable Keyboard Shortcuts

  3. #3
    Junior Member
    Join Date
    Feb 2007
    Posts
    6
    i haven't been able to get this to work. i've been testing it on a browser. any suggestions here? my code looks like this now:

    Code:
    butsubmit.onPress = function(){
      requestForm.name = name_txt.text;
      requestForm.email = email_txt.text;
    
      requestForm.send("requestForm.php","_blank","POST");
    
      name_txt.text = "";
      name_email.text = "";
    };
    
    keyWatch = new Object();
    Key.addListener(keyWatch);
    
    keyWatch.onKeyDown = function(){
      if(Key.getCode() == Key.ENTER){
        requestForm.name = name_txt.text;
        requestForm.email = email_txt.text;
    
        requestForm.send("requestForm.php","_blank","POST");
    
        name_txt.text = "";
        name_email.text = "";
      }
    };
    
    var requestForm:LoadVars = new LoadVars();
    Last edited by bmasar; 02-03-2007 at 04:29 PM. Reason: add info

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    I ran a test file, outputting the LoadVars Object to a textfield,
    it works OK here, can you test and let me Know if working for you ?

  5. #5
    Junior Member
    Join Date
    Feb 2007
    Posts
    6
    thanks, this worked!

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