I am trying to print an integer in JavaScript with commas as thousands separators. For example, I want to show the number 1234567 as “1,234,567”. How would I go about doing this? Here is how I am doing it: Is there a simpler or more elegant way to do it? It would be nice if it works with floats also,
Tag: javascript
Capture key press without placing an input element on the page?
How to capture key press, e.g., Ctrl+Z, without placing an input element on the page in JavaScript? Seems that in IE, keypress and keyup events can only be bound to input elements (input boxes, textareas, etc) Answer jQuery also has an excellent implementation that’s incredibly easy to use. Here’s how you could implement this functionality across browsers: Tested in IE7,Firefox
Limiting the number of characters in a ContentEditable div
I am using contenteditable div elements in my web application and I am trying to come up with a solution to limit the amount of characters allowed in the area, and once the limit is hit, attempting to enter characters simply does nothing. This is what I have so far: This does limit the number of characters to the number
PHP Redirection with Post Parameters
I have a webpage. This webpage redirects the user to another webpage, more or less the following way: Well, you see, what I do is transferring the GET params into POST params. Do not tell me it is bad, I know that myself, and it is not exactly what I really do, what is important is that I collect data
How can I convert a comma-separated string to an array?
I have a comma-separated string that I want to convert into an array, so I can loop through it. Is there anything built-in to do this? For example, I have this string Now I want to split this by the comma, and then store it in an array. Answer MDN reference, mostly helpful for the possibly unexpected behavior of the
how to call javascript function in html.actionlink in asp.net mvc?
How can one call a javascript function in html.actionlink in asp.net mvc? I want to call one method, which is in JavaScript, but how I call it within html.actionlink in the same page? Answer you need to use the htmlAttributes anonymous object, like this: you could also give it an id an attach to it with jquery/whatever, like this:
Using jQuery to gather all text nodes from a wrapped set, separated by spaces
I’m looking for a way to gather all of the text in a jQuery wrapped set, but I need to create spaces between sibling nodes that have no text nodes between them. For example, consider this HTML: If I simply use jQuery’s text() method to gather the text content of the <div>, like such: that produces the following text: List
Align div with fixed position on the right side
I want to show a div which is always visible even as the user scrolls the page. I have used the CSS position: fixed; for that. Now I also want to show the div at the right hand corner of the parent div. I tried to use this CSS code to achieve the goal: But it doesn’t align the element
How to create an array in JavaScript whose indexing starts at 1?
By default the indexing of every JavaScript array starts from 0. I want to create an array whose indexing starts from 1 instead. I know, must be very trivial… Thanks for your help. Answer It isn’t trivial. It’s impossible. The best you could do is create an object using numeric properties starting at 1 but that’s not the same thing.
Drag and drop an image from desktop to a web text editor (implementation in JavaScript)
I want to implement a web text editor able to recognize when the user drag a image file over it’s editing surface and it automa(gically) starts the upload and insert the image near the cursor position. In other words I don’t want the user to do the usual “insert->image->browse->ok”. At the moment I am not very good at JavaScript. I