Gofilord
Gofilord

Reputation: 6641

Chrome alarms don't work with variables?

I am making a chrome extension for notifications, using the notifications API and alarms API. I have tested both and they work, but when I try to set the name of the alarm and it's time from a user input, suddenly it doesn't work at all.
Code:

$('form').submit(function(e) {
    var $request = $('#request');
    var r = $request.val().split(' in '),
            name = r[0],
            amount = r[1];

    console.log('name:' + name + ', amount: ' + amount); // WORKS

    /*
     * WORKS *
    chrome.alarms.create('alarm_test', {
        delayInMinutes: 1
    });
    */

    /* DOESN'T WORK */
    chrome.alarms.create(name, {
       delayInMinutes: amount
    });

    console.log('alarm set.');

    $request.val('');
    return false;
});

This is pretty weird. Thanks for any help :)

Upvotes: 1

Views: 145

Answers (1)

Gofilord
Gofilord

Reputation: 6641

To fix this, all I had to do was the parse amount using parseFloat() method. It now works.

Upvotes: 1

Related Questions