views:

785

answers:

1

Hi all.

I want to make a button in UI iphone (not web iphone) to submit a form (with elements) to Javascipt like the mention below:

  • I have already a javascript file in my page: htpp:/www.myaddress/myfile.js This javascript contain a function called "doTransmit(PIOform)".

  • I want to create a form in UI iphone application consists some fields: txtField1, txtField2,.. and a button. That UI form like a html form below:

    < form name=PIOForm action="server_address" >
        < input type="text" name="txtField1">
        ......
    < / form>
    < input type="submit" value ="submit" >

  • when i click that UI button, it will call doTransmit(PIOform) function from javascript myfile.js above. (note: myfile.js will get and process parameters from UI iphone)

How can i do with button to submit UI form to javascript? Please help me.

Thank you so much.

+1  A: 

Why are you not just using NSURLConnection to submit the form data? You'd have to populate the data in the Javascript form anyway, so it's not like using the javascript to do the submit is saving you anything.

A UIWebView allows you to call javascript methods if you wish, but it's very unlikely you really want to do that.

Kendall Helmstetter Gelner
Thank you Kendall. Yes, I can use NSURLConnection to submit the form data. But i want to try call javascript from iphone as other way. Now i still don't know the way to call javascript methods in iphone.
The only way is to use the UIWebView - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script method. You have to have a UIWebView to run Javascript.
Kendall Helmstetter Gelner