1

So I have the following file which contains the following javascript

(function getradiovalue(myvalue)
{

alert(myvalue);
return myvalue;
})

My .m file contains the following

NSString thisinputradio = @"radio1";
NSString *tstr = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"getRadioValue" ofType:@"txt"] encoding:NSASCIIStringEncoding error: &error] ;

NSString *injectstr = [webView stringByEvaluatingJavaScriptFromString:tstr] ;
NSString *myjscript = [NSString stringWithFormat:@"getradiovalue('%@');", thisinputradio];
NSString *evalstr = [webView stringByEvaluatingJavaScriptFromString:myjscript] ;

This should throw my alert with the value that I have assigned to thisinputradio but I'm getting nothing. I threw an NSLog(@"%@", tstr); and it spits out the javascript code but when I evaluate the second half to pass a variable into the function i get squat. Any Help is much appreciated. I would like to be able to pass something into the getradiovalue function multiple times which is why I have it broken apart this way.

1 Answer 1

1

Remove the first and last brackets from around your function.

Sign up to request clarification or add additional context in comments.

Comments

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.