Skip to content
Advertisement

How can I loop through a JavaScript object array?

I am trying to loop through the following: I want to retrieve msgFrom and msgBody I’ve tried: But the console log prints [Object] Any ideas what im doing wrong? Answer It appears you may just have missed the “messages” property in the data, so the loop is likely iterating the root Object rather than the Array: Unless data was set

How to force input to only allow Alpha Letters?

using jQuery here, however unable to prevent numbers from being typed into the input field http://codepen.io/leongaban/pen/owbjg Input jQuery I’ve seen plenty of examples here on how to restrict to only Numbers, and I’m using the correct key codes for a-z and A-Z. Do you see what I’m doing wrong? Answer The property event.key gave me an undefined value. Instead, I

Stop form refreshing page on submit

How would I go about preventing the page from refreshing when pressing the send button without any data in the fields? The validation is setup working fine, all fields go red but then the page is immediately refreshed. My knowledge of JS is relatively basic. In particular I think the processForm() function at the bottom is ‘bad’. HTML JS Answer

How to fire an event on class change using jQuery?

I would like to have something like: Answer There is no event raised when a class changes. The alternative is to manually raise an event when you programatically change the class: UPDATE – 2015 This question seems to be gathering some visitors, so here is an update with an approach which can be used without having to modify existing code

Passing string variable with spaces

In the following code: ‘set’ is a string variable which can have spaces in it. I’m noticing when it has spaces it’s not working correctly. How can I fix this? EDIT: For clarity, I’d like to keep the spaces intact. Answer You have to replace intermediate space (‘ ‘) with ‘%20’ using replace(), and eliminate boundary spaces (‘ ‘) using

Advertisement