Skip to content
Advertisement

Getting the last element of a split string array

I need to get the last element of a split array with multiple separators. The separators are commas and space. If there are no separators it should return the original string. If the string is “how,are you doing, today?” it should return “today?” If the input were “hello” the output should be “hello”. How can I do this in JavaScript?

How to: Back button support “Ajax”

I have an asp.net ajax website, it full of things happen on the same page without page reload, such as sorting records, paging,… When the user go to another page in the same site and press the browser back button, how can i make the browser save the page state to return to it with the preselected options such as

JavaScript equivalent to printf/String.Format

I’m looking for a good JavaScript equivalent of the C/PHP printf() or for C#/Java programmers, String.Format() (IFormatProvider for .NET). My basic requirement is a thousand separator format for numbers for now, but something that handles lots of combinations (including dates) would be good. I realize Microsoft’s Ajax library provides a version of String.Format(), but we don’t want the entire overhead

Associative arrays in javascript

I have this object: Its used in this way: The problem is, in the addField() function the fields array is being set correct (perhaps because a numerical index is being used to refer to it) but the other 2 arrays (labels and rules) aren’t being touched at all. Doing a console.log shows them as empty in firebug. What do I

How to load up CSS files using Javascript?

Is it possible to import css stylesheets into a html page using Javascript? If so, how can it be done? P.S the javascript will be hosted on my site, but I want users to be able to put in the <head> tag of their website, and it should be able to import a css file hosted on my server into

Get next / previous element using JavaScript?

How do I get the next element in HTML using JavaScript? Suppose I have three <div>s and I get a reference to one in JavaScript code, I want to get which is the next <div> and which is the previous. Answer Well in pure javascript my thinking is that you would first have to collate them inside a collection. So

Trying to wrap my head around custom events

I’m trying to get my head around custom events. I understand how to register and trigger custom events. However, it seems like its not possible to register truly custom events. Everything has to trace back to a DOM event like click, onload, blur, etc. Or am I wrong? For example, suppose I have an array. I want to register an

Advertisement