Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
I have an app which has a UIWebView which is a quiz with dropdown boxes. At the bottom there is a button within the HTML which calls a JavaScript function to show which questions were answered correctly. At this point, I need to save the user's score. If all the questions are correct, I'd like to mark that that section is finished. Is there any way I could trigger an action from the UIWebView to the view controller when a user has answered all questions correctly? Any help would be greatly appreciated. Thanks!
I have an app which has a UIWebView which is a quiz with dropdown boxes. At the bottom there is a button within the HTML which calls a JavaScript function to show which questions were answered correctly. At this point, I need to save the user's score. If all the questions are correct, I'd like to mark that that section is finished. Is there any way I could trigger an action from the UIWebView to the view controller when a user has answered all questions correctly? Any help would be greatly appreciated. Thanks!
In your JavaScript function call:
window.location = "MYDUMMYURL?";
Then in your webView's delegate implement the shouldStartLoadWithRequest method and then do whatever you need to and return NO if it's calling MYDUMMYURL.
Then in your webView's delegate implement the shouldStartLoadWithRequest method and then do whatever you need to and return NO if it's calling MYDUMMYURL.
Hi, sorry, got sidetracked by another project for a month and now I'm back to this one. Here is my JavaScript code:
function checkAnswers() { // So far all answers are correct. var allCorrect = true; for ( var selectIndex = 0; selectIndex < document.theForm.elements.length; selectIndex++ ) {
curSelect = document.theForm.elements[selectIndex]; if ( curSelect.name == \"quiz\" ) { for ( var optionIndex = 0; optionIndex < curSelect.options.length; optionIndex++ ) { if ( curSelect.options[optionIndex].selected ) { // Display checkmark for correct answers and an red X for wrong answers. var answerResult = curSelect.options[optionIndex].value; document.images[selectIndex].src = answerResult + \"25.png\"; if ( answerResult == \"wrong\" ) { allCorrect = false; } } } } } }
This function basically determines which questions were answered correctly and then places a checkmark or X next to them. When a user finally gets all the questions correct, then I need to mark the lesson as being finished. Unfortunately I don't see a way of getting a variable's contents from the JavaScript back to my Objective-C application. Is this even possible?
Replies
In your JavaScript function call:
window.location = "MYDUMMYURL?";
Then in your webView's delegate implement the shouldStartLoadWithRequest method and then do whatever you need to and return NO if it's calling MYDUMMYURL.
- (BOOL)webView:(UIWebView*)p_webView shouldStartLoadWithRequest:(NSURLRequest*)p_request
navigationType:(UIWebViewNavigationType)p_navigationType
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThis function basically determines which questions were answered correctly and then places a checkmark or X next to them. When a user finally gets all the questions correct, then I need to mark the lesson as being finished. Unfortunately I don't see a way of getting a variable's contents from the JavaScript back to my Objective-C application. Is this even possible?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeHere's the relevant Objective-C code:
I also just posted this as a tutorial on my blog: iPhone/Web 2.0 » Send a BOOL value from JavaScript to Objective-C.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome