javascript

JavaScript slider

I need to create a 'slider' for a client's site. The slider should allow people to select how many items they want of x item, and show what the price will be based on that. The weird(ish) part is that the ratio of the price increase will go down as the amount of items goes up: 1 item: $100 2 items: +90 = $190 3 items: + 80 = $270 4 ite...

Is there a more accurate way to create a Javascript timer than setTimeout?

Something that has always bugged me is how unpredictable the setTimeout() method in Javascript is. In my experience, the timer is horribly inaccurate in a lot of situations. By inaccurate, I mean the actual delay time seems to vary by 250-500ms more or less. Although this isn't a huge amount of time, when using it to hide/show UI elemen...

Combining different javascript objects rendered by multiple components

I have a component which writes/generates javascript from a server side renderer. This component can be used in multiple times in a same page. However, once the page is loaded I have to collect all the variables or JSO written by this multiple components in the page. How can I do this so that I will have a collection of all the variables...

How do I load the contents of a text file into a javascript variable?

I have a text file in the root of my web app http://localhost/foo.txt and I'd like to load it into a variable in javascript.. in groovy I would do this: def fileContents = 'http://localhost/foo.txt'.toURL().text; println fileContents; How can I get a similar result in javascript? ...

Hardest javascript debugging problem ever

We have an ASP.NET application and when running on client site they often get null reference Javascript errors. As with all these errors the information IE6 displays is less than helpful. But the problem is as soon as I install IE script debugger and try and debug a bit more the error becomes non-reproducible.When script debugger is not ...

Are browser based online games possible?

I'm not talking about BB-type text based but rich rpgs with spriting, etc. With the current advancements in javascript for rich browser interfaces, would it be possible to create semi-massive multiplayer online games running on our browsers within the near future? We could say that if we really want games we must stick with c++, but I'...

jQuery get select option text

Alright, say I have this: <select id='list'> <option value='1'>Option A</option> <option value='2'>Option B</option> <option value='3'>Option C</option> </select> What would the selector look like if I wanted to get "Option B" when I have the value '2'. Please note that this is not asking how to get the selected text value, but just a...

Where to place Javascript in a HTML file?

Say I have a fairly hefty javascript file*, packed down to roughly 100kb or so, where's the best place to put this in the HTML? <html> <head> <!-- here? --> <link rel="stylesheet" href="stylez.css" type="text/css" /> <!-- here? --> </head> <body> <!-- here? --> <p>All the page content ...</p> <!-- or here? --> </...

Match Regex with Javascript

I need to match something in the form <a href="pic/5" id="piclink"><img src="thumb/5" /></a> to find the number, in this case 5, using javascript. I have no idea how to use regexes so I was wondering if anyone here could help out. Thanks! ...

How to ensure user submit only english text

I am building a project involving natural language processing, since the nlp module currently only deal with english text, so I have to make sure the user submitted content (not long, only several words) is in english. Are there established ways to achieve this? Python or Javascript way preferred. ...

What is the best way to trim() in javascript

The question says it all; JS doesn't seem to have a native trim() method. ...

Where does jQuery UI fit in MVC?

I need to develop a generic jQuery-based search plugin for the ASP.NET MVC application I'm building, but I can't figure out how it's supposed to fit, or what the best practice is. I want to do the following: $().ready(function() { $('#searchHolder').customSearch('MyApp.Models.User'); }); As long as I have implemented a specific i...

Convert string to proper case with javascript

Is there a simple way to convert a string to proper case? E.g. john smith becomes John Smith. I'm not looking for something complicated like John Resig's solution, just (hopefully) some kind of one- or two-liner. ...

What is the easiest way to learn ActionScript when you know JavaScript?

Hi, I am an Ajax developer and I want to build a Flash application. Given my previous experience with JavaScript, what do you thing will be the easiest way to learn ActionScript and what are the obstacles I might encounter? ...

PHP Static variable not working as expected

This example is from php.net: <?php function Test() { static $a = 0; echo $a; $a++; } ?> And this is my code: function getNextQuestionID() { static $idx = 0; return $idx++; } And I use it in JavaScript: 'quizID=' + "<?php echo getNextQuestionID(); ?>" Returns 0 everytime. Why? ...

How do you optimise your Javascript ?

Well... simple question, right? But with no so simple answers. In firefox i use firebug console (profile) but... what to do in other browsers? Like Internet Explorer / Opera / Safari (on windows) ...

Flash Organisation Chart

I've been searching for a library that can render organisation charts in either flash and/or javascript(preferably jQuery). I know of several javascript and/or flash chart libraries but none of them seem to be able to render an organisation chart such as this: http://www.fsai.ie/images/org_chart.gif ...

JQuery drag and drop - how to get at element being dragged

Hi, I am using the JQuery libs to implement drag and drop. How do I get at the element that is being dragged when it is dropped? I want to get the id of the image inside the div. The following element is dragged: I have the standard dropped function from their example $(".drop").droppable({ accept: ".block", ...

Javascript alert boxes combined with PHP

echo "<td><a href='delete.php?id=$row[id]&&category=$a' onclick='return confirm(\'are you sure you wish to delete this record\');'>delete</a></td>"; Above is the code i am trying to use. Every time it does nothing and i cannot see how i can use 'proper' javascript methods. Any help would, as usual, be much appreciated. Cheers guys! ...

Making a Table Row clickable

I wonder what the best way to make an entire tr clickable would be? The most common (and only?) solution seems to be using JavaScript, by using onclick="javascript:document.location.href('bla.htm');" (not to forget: Setting a proper cursor with onmouseover/onmouseout). While that works, it is a pity that the target URL is not visible i...