views:

22

answers:

0

I've implemented the notification alert in an iphone project using phonegap. I've tried the direct, quick, and full examples listed on their api page: http://docs.phonegap.com/phonegap_notification_notification.md.html

The problem is that when the event fires, it fires multiple times. Twice on iphone 3gs, and 3 times on iphone 3g. I'm calling in an if else event like so:

if($('input:radio:checked').length == count) {
<!-- ... -->
} else { showAlert(); return true; }

have also tried { showAlert(); }, and putting the whole function in there... but every time - the event fires twice when run on the device. Meaning I have to dismiss the alert once, and then once more.

Is there something I can add to ensure it only sends one alert?

example code in header (js):

function showAlert() {
    navigator.notification.alert(
        'Please answer all questions.',  // message
        'Almost there!',            // title
        'Okay'                  // buttonName
    );
}

example code in body (alongside form):

<!-- form body... -->
<span class="btncontainer"><input href="#" type="button" value="Click to see your results" class="btn" onclick="getProduct();"></span>
  </form>
  <script type="text/javascript" charset="utf-8">
  function getProduct() {
    //check the form has been filled completely
    var names = {};
    $('input:radio').each(function() { // find unique names
          names[$(this).attr('name')] = true;
    });
    var count = 0;
    $.each(names, function() { // then count them
          count++;
    });
    if($('input:radio:checked').length == count) {
    // Form has been completed  
        // Get scores
        var $radio1 = $('input[name=q1]:checked');
            var a1 = $radio1.val();
        var $radio2 = $('input[name=q2]:checked');
            var a2 = $radio2.val();
        var $radio3 = $('input[name=q3]:checked');
            var a3 = $radio3.val();
        var $radio4 = $('input[name=q4]:checked');
            var a4 = $radio4.val();
        var $radio5 = $('input[name=q5]:checked');
            var a5 = $radio5.val();
        // Calculate the scores
        var userCalc = parseInt(a1) + parseInt(a2) + parseInt(a3) + parseInt(a4) + parseInt(a5);
        // Suggest a product based on scores
        if (userCalc <= 99) {
            jQT.goTo("#ocn", "dissolve");
        } else if (userCalc <= 199) {
            jQT.goTo("#otetof", "dissolve");
        } else if (userCalc <= 399) {
            jQT.goTo("#ocd", "dissolve");
        } else if (userCalc <= 999) {
            jQT.goTo("#odtcfm", "dissolve");
        } else if (userCalc <= 4999) {
            jQT.goTo("#orsc", "dissolve");
        } else if (userCalc <= 30000) {
            jQT.goTo("#otes", "dissolve");
        } else {
            alert(userCalc);
        }
    } else { showAlert(); return true; }
    // End functions
  }
  </script>