In Android, How Can I Set The Value Of A Edit Box In WebView Using Javascript
Solution 1:
The problem is solved. It was because of the way I call javascript in java code.
code like
mWebView.loadUrl("javascript: [your javascript code]");
sometimes work, but it doesn't work in all the case. At least it doesn't work for the following case when I tried to set the textbox in a webview:
mWebView.loadUrl("javascript: document.getElementById('xxxxxxxx').value= 'test'");
but it should work if you call the javascript as a function:
mWebView.loadUrl("javascript: (function() {document.getElementById('xxxxxxxx').value= 'test';}) ();" );
That fixed my problem. Hope it is helpful.
Solution 2:
This worked perfectly for me:
String ABC="50";
myWebView.loadUrl("javascript: (function(){document.getElementById('countLiveSteps').value ='" + ABC + "';})();");
Solution 3:
I would imagine you are running the command before the page is loaded or it cannot resolve document itself. You should write this code as a function included in your document and then have android do:
mWebView.loadUrl("javascript: myFunction('test')");
Or better still, use @JavascriptInterface
Solution 4:
Use the setText() function of TextView as in:
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
Where 'message' is a String variable, this will put the value of message into the textView box replacing anything that was in there previously. I got this example from the code at the bottom of this page https://developer.android.com/training/basics/firstapp/starting-activity.html
EditText uses the same setText() method
Post a Comment for "In Android, How Can I Set The Value Of A Edit Box In WebView Using Javascript"