title: How we can execute a javascript function and get a return value in our android application?
body: <p>How we can execute a javascript function and get a return value in our android appplication ?</p>
  
  <p>We want to execute a javascript on a button press event, we need to pass parameters to the script and get return values, So we are using "WebChromeClient" to implement this, 
  But we got Exception is "SyntaxError: Parse error at undefined:1"</p>
  
  <p>Following is my code</p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.webkit.JsResult;
  import android.webkit.WebChromeClient;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  
  public class FirstTab extends Activity 
  {
  
  
      private WebView webView;
  
      public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
               setContentView(R.layout.regis);
  
              try{
  
                  webView = (WebView) findViewById(R.id.webView1);
                  webView.getSettings().setJavaScriptEnabled(true);
                  webView.setWebChromeClient(new MyWebChromeClient());
                  String customHtml = "&lt;html&gt;&lt;head&gt;&lt;title&gt;iSales&lt;/title&gt;&lt;script type=\"text/javascript\"&gt; function fieldsOnDelete(){ var x=123; return \"JIJO\"; } &lt;/script&gt;&lt;/head&gt;&lt;body&gt;hi&lt;/body&gt;&lt;/html&gt;";
                  webView.loadData(customHtml, "text/html","UTF-8");  
  
                  }catch(Exception e)
                  {
                       Log.v("JAC LOG",e.toString());
                  }
  
          }
      public void onResume()
      {
          super.onResume();
  
              final Button button = (Button) findViewById(R.id.button1);
               button.setOnClickListener(new View.OnClickListener() {
               public void onClick(View v) {
                   try{
                      webView.loadUrl("javascript:alert(javascript:fieldsOnDelete())");
                   }
                   catch(Exception e)
                   {
                       Log.v("JAC LOG",e.toString());
  
                   }
                } 
               });
      }
  
  
      final class MyWebChromeClient extends WebChromeClient {
          @Override
          public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
  
          Log.v("LogTag", message);
            result.confirm();
            return true;
          }
      }
  
  
  }
  </code></pre>