I'm using this code to set the HTML textbox value using Javascript function. But it seems to be not working. Can anyone point out, what is wrong with this code?
Whats your Name?
<input id="name" value="" />
<script type="text/javascript">
function setValue(value){
var myValue=value;
document.getElementsById("name").value = myValue;
}
</script>
the "value" is came from my android java class using this codes
String value = "Isiah";
WebView web = (WebView) findViewById(R.id.web1);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("file:///android_asset/www/webpage");
web.loadUrl("javascript:setValue("+ value +")");
document.getElementsByName("name").value = value"after\"Javascript\">? (and the backslashes)getElementsByNamereturns aHTMLCollectionand not a DOM element, let alone you don't have any element with that name. UsegetElementByIdinstead. Also, you don't ever call the function. It'd be better if you explicitly tell us what you're expecting your function to do.getElementsByIdshould begetElementById(without the extra s). Also the function is never called.