title: Calling JS Function on Form Submit
body: <p>I have created a JS function which executes fine when it's included an the 'onclick' action of standard HTML link tag as follows:</p>
  
  <pre><code>&lt;a href="#" onclick="return fb_CheckPermission('publish_stream');"&gt;test&lt;/a&gt;
  </code></pre>
  
  <p>However where I really want to use this function is on the 'onsubmit' action of a form but when I include it as follows the function no longer seems to be executing:</p>
  
  <pre><code>&lt;form action="page.pl" id="disable-submit" name="status-form" method="POST" onsubmit="return fb_CheckPermission('publish_stream');"&gt;
  </code></pre>
  
  <p>What the 'fb_CheckPermission()' JS function basically does is use Facebook Connect to check to make sure the user has granted us a specific permission and if not it tells Facebook Connect to prompt the user to grant the permission. Here is the code for the JS function:</p>
  
  <pre><code>1. function fb_checkPermission(permission) {
  2.  FB.ensureInit(function() {
  3.      FB.Facebook.apiClient.users_hasAppPermission(permission, function (hasPermissions) {
  4.          if(!hasPermissions){
  5.              FB.Connect.showPermissionDialog(permission,function (status){
  6.                  if(!status) {
  7.                      if(permission == 'offline_access') {
  8.                          // save session
  9.                      }                       
  10.                 }
  11.             });
  12.         }
  13.     });
  14. });
  15.}
  </code></pre>
  
  <p>What this code does is as follows:</p>
  
  <pre><code>Line 2: Make sure Facebook Connect JS library is loaded
  Line 3: Checks to see if the current Facebook Connect user has granted a specific permission
  Line 5: If the permission hasn't been granted then prompt the user with the permission dialog
  Line 7: In the case of the 'offline_access' permission save the session key once granted
  </code></pre>
  
  <p>The user experience I'm trying to achieve is that when a user submits the form I'll check to see if they have granted a specific permission and if not prompt them for the permission before submitting the form. If the user has already granted the permission the form should just submit. For those users who are prompted the form should submit after they either choose to grant the permission or if the deny the request which I believe the fb_checkPermission() JS function is handling correctly right now. What I'm not sure is if there is some kind of JavaScript issue with how this works on form submission.</p>
  
  <p>As I mentioned, this JS function works perfectly as an onclick action but fails as an onsubmit action so I'm pretty sure that this has something to do with how JavaScript treats onsubmit actions.</p>
  
  <p>I'm stuck so I really appreciate your help in figuring out how to change the JS function to produce my desired user experience. Thanks in advance for your help!</p>