Intel XDK JavaScript gives out an error of 'alert is not defined (w117)

125 Views Asked by At

I m a newbie to programming in JS, i though of giving a try in intel XDk. I browsed some videos and according to one tutorial, i followed the exact same steps as he did, But unfortunately, he got the script in emulator working while mine got stuck with a problem of `alert is not defined (W117)' but he didn't got that error,.

My JS code as follows:

/*jshint browser:true */
/*global $ */(function()
{
 "use strict";
 /*
   hook up event handlers 
 */
 function register_event_handlers()
 {


     /* button  #submit */
    $(document).on("click", "#submit", function(evt)
    {
        /* your code goes here */ 

        var name = document.getElementById('name').value;
        var place = document.getElementById('place').value;
        var job = document.getElementById('job').value;
        var gender = document.getElementById('gender').value;
        var reason = document.getElementById('reason').value;

        var text = name + place + job + gender + reason ;
        alert(text);
         return false;
    });

    }
 document.addEventListener("app.Ready", register_event_handlers, false);
})();

Any help is appreciated..

2

There are 2 best solutions below

0
Rafdro On

I don't have your full JS code and cannot find an 'app.Ready' event (which is being run on load looks like). To perform check based on jQuery 'ready' event just use below code:

    $(document).on("click", "#submit", function(evt) {
        var name = document.getElementById('name').value;
        var place = document.getElementById('place').value;
        var job = document.getElementById('job').value;
        var gender = document.getElementById('gender').value;
        var reason = document.getElementById('reason').value;

        var text = name + place + job + gender + reason;
        alert(text);
        return false;
    });
0
xmnboy On

With the 3900 (and later) releases of the XDK there is a known issue where the alert() (and related) functions no longer work inside the Simulate tab. This was due to an upgrade of the version of Chromium that is built into the node-webkit image that underlies the XDK. At this time there is no workaround, other than to use the Cordova dialogs plugin as an alternative.

Note that in some WebViews (the runtime that your Cordova app runs in when it runs on a real device) the alert() function does not exist, since it is an optional feature and not required. Keep in mind that your Cordova app does not actually run in a browser, it runs in an embedded runtime that feels a bit like a browser, but it's not. Just like Node.js apps have a JavaScript runtime engine, so do WebViews, but neither runtime is hosted within a browser.

In general, using the alert() function is not a good option for a real app.