Deselect all options in dropdown with jQuery
Posted on Monday 7 June 2010
Here's how you deselect all the values in a dropdown with jQuery
$("#dropdown").each(function(){
$("#dropdown").removeAttr("selected");
});
Easily embed Flash movies and make them viewable fullscreen with jQuery and SWFobject
Posted on Wednesday 27 January 2010
I wrote a little jQuery script that makes embedding flash movies very easy and makes them go fullscreen when you click a link. I used jQuery swfobject to load in the movies and jQuery to make it go fullscreen. I import the flash videos in a div and set the div’s width and height to 100%. This flash div is outside of a container div. When I make the flash div go fullscreen, I set the display of the container div to none.
Supported browsers:
Internet Explorer 5.5/6.0/7.0/8.0
FireFox 1.5/2.0
Safari 2.0
Opera 9.0
Force break instead of paragraph on new lines in Tiny_mce
Posted on Friday 22 January 2010
Normally tiny_mce inserts a new paragraph when you hit return. You can make tiny_mce force a BR element on newlines instead of inserting a new paragraph. Normally you should utilize P tags instead of BR, so only use this when you have to!
Usage:
tinyMCE.init({
force_br_newlines : true,
...
});
How to force plaintext insertion on paste in tiny_mce
Posted on Sunday 10 May 2009
Several clients of ours seem to type the text for their websites in a Word document fires and copy them afterwards in tiny_mce. Apparently tiny_mce copies the layout from word or any other program so the layout in your website gets messed up. I found a solution for this. You have to enforce pasting as plaintext which removes all markup when you paste something within tiny_mce.
copy these lines within your init function:
//force text to be pasted as plaintext
setup: function(ed) {
ed.onPaste.add( function(ed, e, o) {
ed.execCommand('mcePasteText', true);
return tinymce.dom.Event.cancel(e);
});
},
Focus on first form input field or textarea onload page using jQuery
Posted on Thursday 9 April 2009

This Javascript basically only sets the focus on the first form input field or textarea of a form when the page is loaded. i use this in my CMS because I hate it when I e.g. have to manually type in a list of emails in a form always click in the first input field to start typing again. This script uses jQuery.
Limiting the length of characters in a textarea using javascript
Posted on Wednesday 8 April 2009

I use a javascript that‘s very easy to use. All you need to do is include the JS file and add a maxlength attribute to a textarea element with the amount of characters you want to allow. That‘s it. I use this to limit the input of characters for page meta-tags to 160 characters.
e.g.
< textarea cols="60" name="field" rows="3" maxlength="160">
And add onload=‘setMaxLength()’ to the body tag:
< body onload="setMaxLength()">
How to make a simple jQuery Ajax request
Posted on Monday 9 March 2009

jQuery is an amazing javascript framework. It‘s makes Ajax so easy. You don‘t have to know anything about Ajax to use it. I‘ve made a simple example on how to use jQuery to make an Ajax request. First, start with creating a database with the name jquery_ajax. I‘ve included the sql dump in the example. In the database there‘s 1 table, called comments. Then we‘ll need to include jQuery in our html file. Next, add a div with a class loading. In the css file the loading class is hidden so we‘ll use
to hide it. You can call the jQuery.approve() function on whatever DOM element you like. Here we‘ll pass on 1 parameter (the id of the comment to be approved) to the function.
input id=“1” onclick=“jQuery.approve(1);” type=“submit” value=“Awaiting approval”
Allow only numeric input or disallow spaces with Javascript
Posted on Wednesday 11 February 2009

This is a very easy way to restrict users from inputting any characters other then numbers or restrict users from entering spaces in e.g. login and password fields. You can restrict other characters by adding the charcodes to the function. You can check the charcodes at cambiaresearch.com
You can download the files below.
Usage:
Load in the javascript file and add onkeypress=“return isNumberKey(event)” in the input tag.
like so:
input type=“text” name=“numeric” id=“numeric” value=”” maxlength=“12” onkeypress=“return isNumberKey(event)”