Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone - Getting data from uiwebview textfield

Tags:

Am developing an app which load a HTML page into uiwebview - that html file contains text-filed and drop-down list, text-boxes etc..

Here How to get values which user has entered in that text-filed and answers selected from drop-down(picker).

Thanks

like image 797
nik Avatar asked May 06 '11 08:05

nik


People also ask

What is a UIWebView Iphone?

A view that embeds web content in your app.

What is UIWebView WKWebView?

Overview. A WKWebView object is a platform-native view that you use to incorporate web content seamlessly into your app's UI. A web view supports a full web-browsing experience, and presents HTML, CSS, and JavaScript content alongside your app's native views.

How can I clear the contents of a UIWebView WKWebView?

To clear old contents of webview With UIWebView you would use UIWebViewDelegate 's - webViewDidFinishLoad: .

How do I use WKWebView?

Here's how: Open the XIB or Storyboard you want to add the web view to in Interface Builder. Find the web view or WKWebView in the Object Library at the bottom-left of Interface Builder. Drag-and-drop a WKWebView object from the Object Library to your view controller's canvas, and adjust its size and position.


2 Answers

You can use [UIWebView stringByEvaluatingJavascriptFromString:] method and get the values by executing the javascript.

Example: If your html is:

<html>   <body>       <input id="myId" type="text" value="TextValue"/>   </body> </html> 

Following code can get you the value of the text field:

   NSString* value = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('myId').value"]; 
like image 140
Udayakumar Rayala Avatar answered Oct 10 '22 11:10

Udayakumar Rayala


You can either poll a javascript function inside the page (using UIWebView stringByEvaluatingJavascriptFromString:).

Or you could call an objective-c method directly from the page using a little hack: UIWEBVIEW SECRETS - PART3 - HOW TO PROPERLY CALL OBJECTIVEC FROM JAVASCRIPT
(scroll down to the bottom for github-link).

like image 20
iceydee Avatar answered Oct 10 '22 10:10

iceydee