0

I am showing a web page using html string in a UIWebview. I want to retrieve the value typed from the below text area code.

result = [result stringByAppendingFormat:@"<textarea name=\"qId_"];
    NSString *questionid = [question valueForKey:@"QuestionId"];
    NSString *questionidSTR = (NSString *) [NSString stringWithFormat:@"%@", questionid];
    result = [result stringByAppendingFormat:questionidSTR];
    [questionidArray addObject:questionidSTR];
    result = [result stringByAppendingFormat:@"\" rows=\"5\" style=\"width:90%\"></textarea>"];

I tried

NSString  *value = [NSString stringWithFormat:@"%@%@%@",@"document.getElementById('",[questionidArray objectAtIndex:i],@"').value"];

   NSString* out = [enterSurveyWebview stringByEvaluatingJavaScriptFromString:value];

But, its not giving the correct output, i think i'm doing wrong when retrieving the value.

Could someone please correct me for retrieving portion?

Thank you.

1 Answer 1

2

Your <textarea> has a name of qId_%@ (where %@ is the QuestionId), but your javascript is only asking for %@. You also need to be using getElementByName() instead of getElementById().

NSString *value = [NSString stringWithFormat:@"document.getElementsByName('qId_%@')[0].value", [questionidArray objectAtIndex:i]];
Sign up to request clarification or add additional context in comments.

4 Comments

I tried correcting it, result=[NSString stringWithFormat:@"%@qId_%@%@",@"document.getElementById('",[questionidArray objectAtIndex:i],@"').value"]; but its not getting the value.
@Getsy: I think you want getElementByName()
Sorry, make that getElementsByName().
Either result = [NSString stringWithFormat:@"document.getElementByName('%@').value", [questionidArray objectAtIndex:i]]; (or) result = [NSString stringWithFormat:@"document.getElementByName('qId_%@').value", [questionidArray objectAtIndex:i]]; , both are not giving the actual result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.