I am trying to simply check if I have an empty input text box but I get this error when I run this in Chrome: Uncaught TypeError: Cannot read property ‘length’ of undefined. Here is how I go about doing it. I check for DOM readiness and then call the function: Answer The id of the input seems is not
Tag: javascript
Javascript Regular Expression Remove Spaces
So i’m writing a tiny little plugin for JQuery to remove spaces from a string. see here my regular expression is currently [ ]+ to collect all spaces. This works.. however It doesn’t leave a good taste in my mouth.. I also tried [s]+ and [W]+ but neither worked.. There has to be a better (more concise) way of searching
from green to red color depend on percentage
I have a poll system and I want answers for this poll to be colored. For example: If it’s 10% it would be red, if 40% it would be yellow and if 80% it would be green, so I want my javascript code to use the rgb colors to make a color according to the given percentage. Now I want
missing ) in parenthetical
I keep getting that my javascript is missing ) in parenthetical [Break On This Error] if ( (this.scrollTop < this.scrollH…uches[0].pageY > scrollStartPosY+5) ) And I cannot for the life of me figure out why. Answer Try JS Lint. It’s great for finding non-obvious syntax errors on scripts.
looping through arrays of arrays
I have an arrays of arrays (some thing like graph), How to iterate all arrays? Its just an example array, actual can contains any number of array and then arrays. How to print all those numbers? Its similar to html objects DOM Answer This recursive function should do the trick with any number of dimensions:
How to count active javascript timeouts?
I am using Selenium to test a web app that uses Dojo, and it uses java script to display certain elements. I want to wait until all of the elements are desplayed before I try to manipulate the page, however I am having trouble. I have started by waiting for the dojo inFlight variable to be 0, this says that
How can I validate that someone is over 18 from their date of birth?
I am doing validation for Driver’s Date of birth, it should be minimum of 18 from the current date. I am using this above JavaScript validation for checking a person’s DOB above 18, but it is not correct. I need to check with today’s date and it should be above 18. How can I compare and check with the current
javascript – shuffle HTML list element order
I have a list: Using javascript how can I reorder the list items randomly? Answer This is based on Fisher–Yates shuffle, and exploits the fact that when you append a node, it’s moved from its old place. Performance is within 10% of shuffling a detached copy even on huge lists (100 000 elements). http://jsfiddle.net/qEM8B/
Disable button whenever a text field is empty dynamically
Here’s my code: This works but still not efficient since the user can delete the text inside the text box and click the button while he’s holding on DELETE key. Is there a more efficient way to achieve this using javascript? Answer Add a check when the button is clicked to see if there is any text. If there isn’t,
window.close() after page redirect
I am on a work intranet only having to support IE8. I am creating a page called “watch video” which (as the name suggests) serves a video to the client. A page linking to a video will open this page in a popup with the link in the url. The person accessing the video (and a datetime stamp) is then