Reputation: 1934
How can I physically put some text from a UITextField into a form in a UIWebView in my iOS app? Maybe a javascript string could be called to input the text?
Thanks!
Upvotes: 2
Views: 2845
Reputation: 1977
Like Matt H suggested, you need to inject your javascript. So there are basically two parts to this problem. 1st you have your objective C.
NSString *username = @"Fred";
NSString *password = @"pAssw0rd";
NSString *jsCallBack = [NSString stringWithFormat:@"updateWebForm('%@,%@');",username,password];
[self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
Then you will have your javascript function, i put mine in a .js file, that my webview page is linked to.
updateWebForm(username,password)
{
//here is where you will assign whatever html/javascript needed for your form.
}
Upvotes: 3
Reputation: 6532
You can inject Javascript into a UIWebView:
[webView stringByEvaluatingJavaScriptFromString:@"javascript goes here"];
Use that with $('#fieldid').val('fromuitextfield'); or with document.getElementById() or however you need to change the text field value property.
Upvotes: 1