I have implemented in a form a number type input, with specified min and max : The input type number works : if something else then a number is entered or if the number value is not in the specified range, the input becomes Red. I have a javascript function that submit the form on input change. I would like
Tag: javascript
My JavaScript isn’t changing className property
Here is the main part of my code attempting to toggle class on a p tag (info) on click of my button (btn). I’m not sure what I’m doing wrong. I have never used the className property before so I’m not sure if I’m missing something simple, or if there is fundamental error in my logic tr…
‘unsafe-eval’ on chrome extension
I am trying to run the following: Which should (in theory), on page load run the loadScript.js file…. the loadScript.js file is as follows, this should append a file to the running page, not to the background page as it is at the moment: I am still a newbie to Chrome Extensions and .js so excuse me if I…
jquery bootstrap selectpicker refreshing lists based upon previous list choice
I have three drop down lists, one list is populated on page load and doesn’t change. The 2nd and 3rd lists may change depending on the selection. This functionality is working fine. I have tried to add Bootstrap selectpicker to the selectors and I can see it is working – unfortunately the lists ar…
Uncaught TypeError: Cannot read property ‘substr’ of undefined
Pardon me for not being clear, but have thia script that is really long. When I have it live, I get this error in Chrome’s Console. Uncaught TypeError: Cannot read property ‘substr’ of undefined here is the snippet of code where it is reading from. I looked up substr on google and it appears…
jQuery unbind after first click
This causes multiple buttons to take action: When fileThisEmail runs, I’d like to remove it from ONLY the current one (there are others on the page that still need it): I tried off, but couldn’t seem to get it right. Any ideas? Answer In this case, you have to make the current element no longer ma…
Convert number of days into years, months, days
I have two date pickers that calculates the number of days there are between the two dates. At the moment I’m outputting the number of days (see code below) which is kind of meaningless. I want to output that number in years, months, days. How can I do that? E.g So 01/01/14 to 01/02/15 = 397 days which …
Mongoose find/update subdocument
I have the following schemas for the document Folder: So, for each Page I can have many permissions. In my CMS there’s a panel where I list all the folders and their permissions. The admin can edit a single permission and save it. I could easily save the whole Folder document with its permissions array,…
Trim specific character from a string
What’s the JavaScript equivalent to this C# Method: C# trims the selected character only at the beginning and end of the string! Answer One line is enough: A general solution: Parameter c is expected to be a character (a string of length 1). As mentionned in the comments, it might be useful to support m…
Fire event only when clicking on an element, and not on its children
If I bind a click handler to the body element, when I click anything on the page the event is triggered. I can check the event.target on every click: but that seem a bit overkill. Is there a way to trigger the event only when clicking the blank area of the body itself? Answer You can use the eventPhase proper…