javascript

Submit behavior is acting differently when pressing a button compared to pressing enter

I've got this simple login screen where is has a text box for the name, and a submit button. The jquery script running is this: $(document).ready(function() { $('#btnLogin').click( function() { validate() }); $('#loginForm').submit( function() { validate() }); }); function validate() { if ($('#txtLogin').val() != '') { ...

create JSON object using variables for property name

Is it at all possible to use variable names in JSON properties for JSON object ceration? Example CreateJSON("myProperty"); function CreateJSON (propertyName){ var myObject = { propertyName : "Value"}; document.write(myObject.popertyName); // prints "value" document.write(myObject.myProperty); // Does not exist } ...

Advanced search/queue array collection question

I have a pretty large number of objects "usrSession" I store them in my ArrayCollection usrSessionCollection. I'M looking for a function that returns the latest userSessions added with a unique userID. So something like this: 1. search the usrSessionCollection and only return one userSessions per userID. 2. When it has returned x num...

Find value of current line

How can I find the value of the current line of a textarea? I know I have to find the caret position, but then find everything before it up to the last \n and everything after it to the next \n. How can I do this? ...

Conflict between two jQuery plugins?

Hey, I'm developing a couple of jQuery plugins for a client website that will allow the styling of form elements such as radios, checkboxs and selects. I've been developing them as three separate plugins within the same file, and while the radio and checkbox plugins seem to work fine alongside each other, my select one is giving me troub...

What are the most common causes of errors in javascript and how to fix them?

Possible Duplicate: Common programming mistakes for JavaScript developers to avoid? This is kind of a subjective question, but I am hoping the well-tenured programmers might know of solutions. I have noticed now predominately in javascript, or any .js file that causes an error can halt further js from running. This could be a...

$.getJSON (jQuery) not working in IE 8

There is some straightforward AJAX code that works in Firefox and Chrome but not in IE. I am not doing anything fancy but the code is too long to post here. Essentially, it is: <script type="text/javascript"> var baseurl = 'http://mydomain.com/facebook/'; var setUpGame = function(lvl){ var ajaxurl; ajaxurl = baseurl+'ajax.php?f=gg...

xmlhttp request not working

I'm trying to build a basic chat site and have four files: chat.html, scripts.html, load.php, and send.php. Here they are: chat.html: <html> <head> <title>Josh's Python Chat Website</title> <script type="text/javascript" src="chatscripts.js"> </script> </head> <body> <div id="divUsernam...

How does the click() function in jquery work when working with multiple stacked divs?

How does the click() function in jquery work when working with multiple stacked divs? I have one main div and another div inside of the main div, when i click on the div inside, its also considered a click on the main div, but i dont want that, i want it to only consider a click on the inside div. <div id="main"><div id="inner"></div><...

Javascript: RegExp object creation problem

Hi I wish to use the following regex for validating a file-upload: /^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(ext)$/ But i want to be able to specify the ext filter. Is this right? function validateFile(str, ext) { alert(str); var expr = new RegExp("/^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(" + ext.toLowerCase() +...

Determine how many fields a Javascript object has.

I have a Javascript object that I'm trying to use as a "hashmap". The keys are always strings, so I don't think I need anything as sophisticated as what's described in this SO question. (I also don't expect the number of keys to go above about 10 so I'm not particularly concerned with lookups being O(n) vs. O(log n) etc.) The only func...

JavaScript issues with lengthy URLs and special characters

I am using the following code but I have noticed that when I change the dashboard URL array to include lengthy XML URLs that include characters like "#", "-", and "=" and I have several URLs listed in the array, only the first URL is processed and the other two are ignored. For example, the URLs might be like: dashboards: [ {url:"http:...

Getting the 'co-ordinates' of a <TD> cell using jQuery

I'm building somewhat of a different website, below is my HTML markup and my question. Please don't be put off by this wall of text, I'm sure it's really not a difficult problem for someone who know's their stuff but it takes some explaining. <div id="0" class="cell" style="top: 0px; left: 0px;"> <table border="0" cellpadding="0" ce...

Position of first word of string in Javascript

I originally used indexOf to find a space but I want to find any word boundary. Something like this, but what regex? var str = "This is a sentence", firstword = str.search(""); return word; I want to return "This". Even in the case of a tab, period, comma, etc. ...

Javascript code to detect current page

Is there a javascript code that can detect what page my user is on and then add a class to a ul item? I want to put my menu in my static HTML website in a separate file and then use PHP include to add it, but I want class="current" for the current page. ...

With Jquery .click() can I also catch opening in a new tab or window?

To make this simple. I have some text that when you click on it. It then redirects you to home.html. As follows: $('#ElementID').click(function () { $('#ElementID').html('Redirecting...'); parent.location = 'http://' + host + '/home.html'; window.location = 'http://' + host + '/home.html'; }); The actual link ...

what's wrong with .match() javascript

jquery says: http://docs.jquery.com/JQuery_Core_Style_Guidelines#RegExp All RegExp operations should be done using .test() and .exec(). "string".match() is no longer used. Why is .match() not recommended? ...

What on earth is ReverseHTTP and why would it be useful?

reversehttp.net offers little immediate insight into what reversehttp truly is and how this can be best utilized, it makes it seem that this tool is too difficult to realistically implement. In what sorts of environments might this be the ideal real-time web data situation and when would this not work, What browsers support this method, ...

Enumerate CSS style elements using JavaScript

First up, JavaScript is definitely not my native tongue. Nevertheless, I've been tasked with creating a web page where the user can use a colour picker to change CSS elements. These then need to be sent back to the server to be stored in a database. It's all working so far except the last part, because I'm stuck reading the required elem...

Javascript: Is there a way to send a cash drawer kick code?

I'm trying to make a cash drawer kick open. The command that needs to be sent to the drawer, by way of the receipt printer, is "chr(27).chr(112).chr(0).chr(100).chr(250)". Is there a way to send this command through javascript or other web based language. I want the cash drawer to only open only during certain receipt prints. ...