JavaScript
Prevent Enter Key Submitting Forms With JQuery
Fri, 07/15/2011 - 09:35 | by philipnorton42A common practice that some users have is to press the enter key when they are filling in forms on the web. This might be when they are just moving to the next field, but the trouble is that this will submit the form.
To prevent this from happening you can simply stop the form being submitted if the enter key had been pressed. This is done by binding a JQuery event to the input elements of the form and returning false if the key pressed is enter, which has the keyCode value of 13. We also include a call to the JQuery method preventDefault() to stop the event propagating.
Automatically Copying The Node Title To The Menu Title In Drupal 6
Wed, 04/13/2011 - 16:48 | by philipnorton42One new feature of Drupal 7 is that any title you give a node will be copied to the menu title field when you create a menu item. I wanted to replicate this functionality in Drupal 6 and so I created a function that did just that. I have used this function a few times in different projects so I'm posting it here.
Change Text Of Submit Button When Clicked
Fri, 03/19/2010 - 16:11 | by philipnorton42Changing the text of a submit button when clicked can be useful if you are writing an AJAX application or you know that there will be some sort of delay. Providing the user with some form of feedback is a useful way of letting them know they they have done something.
First, we need a form to work with, so I built a quick one here. Notice that the submit button has an onclick action associated with it, this will be used later to enable us to alter the text of the button.
Using JQuery To Open External Links In A New Window
Fri, 02/19/2010 - 10:17 | by philipnorton42Opening external links in a new window can be useful, but adding target="_blank" can be a real chore. Not only that, but if you are trying to validate the page to XHTML strict then the target attribute will cause errors to appear as it is not defined in XHTML.
Scroll To First Error Message On Page With jQuery And ScrollTo
Fri, 01/29/2010 - 10:25 | by philipnorton42If you have a large page or form that uses validation on it then you will probably want to tell the user that something is going on. One way to do this is by telling the user at the top of the page that something has gone wrong and then letting them figure out where.
A more elegant solution is to scroll the page down the just above the first error message so that the user is aware of what they need to fill in. This can easily be done through a combination of jQuery and the ScrollTo plugin.
JQuery Image Switcher
Mon, 12/07/2009 - 21:40 | by philipnorton42Using something like CrossSlide is fine if you want fancy effects in your image translations, but for more simple effects you can use a single function to simply swap one image for another. First, lets create some simple markup that will allow us to display some images.
<div class="slideshow"> <img src="image1.png" alt="Image 1" /> <img src="image2.png" alt="Image 2" /> <img src="image3.png" alt="Image 3" /> <img src="image4.png" alt="Image 4" /> </div>