1

Quick question - if a textfield in a webform, does not automatically has the focus set by the form, ie you got to press the field before the keyboard pops up - am I correct to assume that field cannot be edited then?

In other words - I cannot set a text for a textField by injecting javascript into it, unless it gets a focus upon loading of the website right?

NOTE: I am not talking about set texts or placeholders here:-)

Cheers

jwknz
  • 6,598
  • 16
  • 72
  • 115

1 Answers1

9

Yes you can! You can use Javascript to set the value:

[theWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('textFieldID').value = 'MyText'"]

Here's an article which shows you how to set and get the values of textfields with Javascript.

Hope this helped!

Community
  • 1
  • 1
waylonion
  • 6,866
  • 8
  • 51
  • 92
  • Ok I am taking another crack at it - do I put it in this method? : '- (void)webViewDidFinishLoad:(UIWebView *)webView{' ?? – jwknz May 08 '12 at 20:13
  • 1
    Well, if you want to change the text "upon the loading of the website," then yes, put your method into - (void)webViewDidFinishLoad:(UIWebView *)webView{ so that the method is called once your webview is ready to go! – waylonion May 08 '12 at 20:18