javascript

script loading error

Given piece of code works on firefox but not in Internet explorer. In IE, it says that COMSCORE is not defined. document.writeln('<!-- Begin comScore Tag -->'); document.writeln('<sc'+'ript src="http://someURL/beacon.js"&gt;'); document.writeln('</sc'+'ript>'); document.writeln('<sc'+'ript>'); document.writeln(' COMSCORE.beacon({'); d...

Regular expression for allowing only a certain set of characters

I would like some help creating a regular expression for parsing a string on a textbox. I currently have these two javascript methods: function removeIllegalCharacters(word) { return word.replace(/[^a-zA-Z 0-9,.]/g, ''); } $("#comment").keyup(function() { this.value = removeIllegalCharacters(this.value); }); I would like to rep...

Fill empty spaces in a list element

I have a fluid grid (in height and width). The LIs are always rectangular and adapt them self's to the screen size. Now i need to fill the lists, so they all have the same height. This would be easy if the all the columns had a with of one LI element. But there are double sized columns and some of them can contain big sized LI's. In som...

Resizing a div on button click, should this be done with AJAX?

I want to resize a div from client-side, it's default value is height:500px, clicking my button sets it to height: 700px. It's an asp.net web site. I am asked to do this using AJAX and I am unclear if this means to use the client-side javascript from the Microsoft AJAX Library, or if this means to use server-side AJAX doing a partial ...

jquery: when i click a div, give focus to a textbox.

$('.my-button').click(function() { $(".my-textbox").focus() }); Before Jquery 1.4 this used to be the way to call focus to a textbox, now it doesn't work. When I click the button, I want to call focus to the textbox, what i mean by "focus", is that I want the textbox to act like it was just clicked on, so that the user will not hav...

How to end a regular expression with a forward slash in Javascript

Problem I am trying to match the hash part of a URL using Javascript. The hash will have the format /#\/(.*)\// This is easy to achieve using "new RegExp()" method of creating a JS regular expression, but I can't figure out how to do it using the standard format, because the two forward slashes at the end begin a comment. Is there ...

Notification alert similar to how stackoverflow functions

How does stackoverflow create the slidedown effect to alert a user of a change ? ...

how to write Or condition in javascript?

is it correct?- if (expiryMonth == "MM" || expiryMonth == "mm") { ...

How does the browser / JavaScript same origin policy apply to two-level domain names?

I have some JavaScript that is sharing a request between two separate servers on the same domain. Is .com a requirement for the domain in JavaScript? In this case both the servers are on the .abc.tyy domain with the tyy being what would normally be .com Wondering if I can only use .com for the domain? I am getting a permission denied ...

JavaScript - Shuffling Objects inside an object (randomize)

I need to implement a randomization from JSON result. The format of the JSON is two objects: result: Question(object) [Object { id="4c6e9a41470b19_96235904", more...}, Object { id="4c784e6e928868_58699409", more...}, Object { id="4c6ecd074662c5_02703822", more...}, 6 more...] Topic(object) [Object { id="3jhf3533279827_2342...

Software Engineering Principles with Javascript

We are always trying to improve on our ability to apply our skills to solve a problem. Software engineering principles have significantly helped my ability to write higher quality code. This includes testing, modularization, using OO where appropriate, etc. Here's an example of how I achieved some modularization in my JS. Maybe it is a ...

Subtracting values from multiple input fields

I'm using the following code to take the value of one field, subtract it from the value of another field and display the result. $(document).ready(function() { var numIn; var numOut; var total; $('#submit').click(function() { numIn = $('input.in').val(); numOut = $('input.out').val(); total = ...

Sending lots of data through POST or GET

I am trying to send an XML file from a textfield in my html, via ajax to a PHP file. This is the almighty PHP file: <?php $data = urldecode($_POST["xml"]); echo $data; ?> Data is sent to this file as such: $("#btn_save").click(function() { var data = escape($("#textfield").text()); alert(data); $.ajax({ ...

jQuery UI error .. only in incognito mode?

On this page I am getting an error in Google Chrome but only when incognito mode. It works fine in regular mode. Is there a reason why JavaScript would throw in error only in incognito mode? The error is in the jquery-ui.min.js file. Its an Uncaught SyntaxError: Unexpected token ILLEGAL ...

Jquery: is there a way to create functions in my small bit of code to make this faster/simplier/smaller?

I'm trying to find a way to make this smaller by using functions/variables in my jquery. $('.search-what-category').fadeOut('normal', function(){ $('.search-wrapper').animate({'height':40}) }) $('.search-what-category').fadeOut('normal', function(){ $('.search-wrapper').animate({'height':40}, function(){ $('.search-wra...

Search a multitude of arrays

Hey, I am searching each array separately for specific inputs from a user. if ($.inArray(i.val(), helloInputArray) > -1) { //IF HELLO if (hello == 0) { //HAVE YOU ALREADY SAID HI? r = Math.floor(Math.random()*4); o.html(o.html()+helloOutputArray[...

get the tab text on select jquery ui tabs

Hi I m using jquery ui tabs I can get the index of the selected tab on "load" (ajax) event $('#tabs').tabs( { load: function(e, ui) { if($('#tabs').tabs('option','selected') == 0) { } } }); Now i want to get the tab name for eg... <ul> <li><a href="newprofile.jsp"><span>Profile</span></a></...

Populating a table by ajax is very slow

I have written a web service that returns some data as json. To display this in a table I am using the datatables jquery plugin: for(var i=0;i<results.length;i++){ myTable.fnAddData( [ "<input name='codeSearched' type='radio' value='"+results[i].ID+"' />", "<span id='code_"+results[i].ID+"'>"+ results[i].code+"</>",...

How do you hook an event to a datasource in YUI?

http://developer.yahoo.com/yui/datasource/#events I'm trying to use the responseParseEvent but I don't know how to hook into into my datasource object because YUI doesn't provide any examples. Sidenote: Has anybody else noticed this with YUI? That their documentation doesn't contain nearly as many examples as jQuery? ...

Setting radio boxes to be checked with jQuery

I have a page with some radio buttons that I want to be checked on page load. This is the jQuery that I'm using: $('.optionHolder').find('input').first().attr('checked', 'true'); The one's I want checked are the first input elements of each .optionHolder on the page. At the moment there are two, but the code above is only checking one...