Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6918525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:52:13+00:00 2026-05-27T09:52:13+00:00

Starting off I have UTFS. Trying to insert a variable in the middle of

  • 0

Starting off I have UTFS.

Trying to insert a variable in the middle of string to populate a web view form without using a string by append and making the code huge. My current code is

NSString *html = [webView stringByEvaluatingJavaScriptFromString:@” document.DetailView.innerHTML;” @”document.getElementsByName(‘user_name’)[0].value = ‘somuser’;”
@”document.getElementsByName(‘user_password’)[0].value = ‘somevar’;”
@”document.DetailView.submit();” ]

I have tried

NSString *html = [webView stringByEvaluatingJavaScriptFromString:@” document.DetailView.innerHTML;” @”document.getElementsByName(‘user_name’)[0].value = ‘%@’;”
@”document.getElementsByName(‘user_password’)[0].value = ‘somevar’;”
@”document.DetailView.submit();” , txtField.text];

But it throws me a build error(specifically it’s looking for “]”). I’m guessing I will have to slowly build the string using stringbyappend but i’m hoping for a little luck that someone will have encountered this or have a workaround for it. This seemed so simple in c#.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:52:14+00:00Added an answer on May 27, 2026 at 9:52 am

    You can place variables into a string with stringWithFormat:. In your case, the following would work:

    NSString *html = [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.DetailView.innerHTML; document.getElementsByName('user_name')[0].value = '%@'; document.getElementsByName('user_password')[0].value = 'somevar'; document.DetailView.submit();" , txtField.text]];
    

    There is an additional bug in your code in that you don’t properly encode the text field value – consider what would happen if the user entered an apostrophe.

    However building up JavaScript in this way isn’t a great approach. Consider factoring out the JavaScript into an external JavaScript file – this will make it much easier to read and write.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just starting off Windows OEM development and have come across these two
I'm starting off with NHibernate now and I still don't have a testable environment.
I am starting using FMOD API and I have got problem with sound playing.
My problem is I'm trying to make a console based chess game. Starting off
This is starting to piss me off real bad. I have this XML code:
I am just starting off with android and have been googling high and low
Ok so I am starting off with android development and I have found a
I have a table with some of the rows starting off hidden ( display:none
I am just starting off with the world of programming C#, and have come
I am just starting off with Objective-C and iphone app dev, i'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.