iOS Objective C – UIWebView AutoFill and Execute

I was wondering is there any possible way that I can have a webview that automatically inputs the values for text boxes on a website and submit so that the user can just bypass the search (in particular search forms) entirely? So the user is only shown the result?

An example is : http://www.eatwellguide.org/mobile/
I noticed looking at the source it is using javascript.

  • How to handle “CFNetwork SSLHandshake failed” in iOS
  • Why are PNG images larger in the iOS app bundle than in my project?
  • @property definitions with ARC: Is strong default now?
  • Remove SeparatorInset on iOS 8 UITableView for XCode 6 iPhone Simulator
  • How to merge two UIImages while keeping their position, size and aspect ratios?
  • Can we submit xcode6 beta builds? How to prepare app for iOS8?
  • Is there anyway I can automatically fill those in and press submit without the user even seeing this page. So, the webpage loads up to the results page?

    Thanks in advance!

    In response to the answer:

    Is there any specific place I have to put this code? I put it after I did a load request to the webView for the site I listed above and then after the [super viewDidLoad], I put in the code you listed with values for first value and second value, with nameofOneInput being ‘SearchKeyword’, ‘SearchSubmit’ being the 2nd, and then the form id as ‘frmsAS’? It’s still not working. What am I doing wrong? I actually tried it to execute when the a button is pressed, still did not work

    Solutions Collect From Internet About “iOS Objective C – UIWebView AutoFill and Execute”

    Yes, you can use the following javascript to fill out the form then submit it.

    //Set the values
    NSString* firstValue = @"first value here";
    NSString* secondValue = @"second value here";
    // write javascript code in a string
    NSString* javaScriptString = @"document.getElementById('nameOfOneInput').value=%@;"
    "document.getElementById('nameOfAnotherInput').value=%@;"
    "document.forms['nameOfForm'].submit();";
    
    // insert string values into javascript
    javaScriptString = [NSString stringWithFormat: javascriptString, firstValue, secondValue];
    
    // run javascript in webview:
    [webView stringByEvaluatingJavaScriptFromString: javaScriptString];
    

    You obviously have to set firstValue and secondValue first.