I have written a HTML page which has following code.
<div id="adsListContainer" style="margin: 5px;">
<textarea id="txtDesc" rows="20" cols="50"></textarea>
<br />
<input id="txtCounts" value="0" size="8" />
<input type="button" value="Count" onclick="countChars()" />
</div>
The above html is enclosed in a file named test.html and it's being shown in android's WebView control. Now using Java and WebView's loadURL() function I am executing javascript as to write something in that textarea as following code goes.
javascript:document.getElementsByTagName("textarea")[0].value += 'anything goes here of not more than 50 chars';void(0);
Even thought the above code works and I am calling it many times so I may insert 7000+ characters in this textarea element.
The Java code responsible for executing Javascript to insert text (HTML) into textarea is as follows.
int bStart = 0;
int bEnd = 49;
String description = "some huge description including html tags"
int totalChars = description.length() - 1;
while (bStart <= totalChars) {
if (bEnd > totalChars)
bEnd = totalChars;
rv = "javascript:";
rv += "var tas=document.getElementsByTagName('textarea');"; // description
rv += "if (tas.length>0) {";
rv += "var ta=tas[0];";
rv += "ta.value += '"
+ description.substring(bStart, bEnd)
.replace("'", "\\'").replace('"', '\"') + "';"; // description
rv += "}";
webView.loadUrl(rv + "void(0);");
bStart += 50;
bEnd += 50;
}
Although the above code works but not perfectly. The description has 7245 characters but it only insert 6267 characters into textarea of the web page.
Is there something I am missing?