All of the code samples have now been consolidated and moved to my blog at http://house9.blogspot.com/. Many google searches still point here so I am leaving this blog operational.
Showing posts with label jquery. Show all posts
Showing posts with label jquery. Show all posts

Friday, September 25, 2009

Attribute "target" exists, but can not be used for this element.

These days I am all about valid xhtml and was surprised to receive this validation error when using the target attribute on an anchor tag.
Attribute "target" exists, but can not be used for this element.


I found a nice work around that does not involve window.open, using jquery we can hack the attribute on 'after' the dom has loaded.



Now instead of target='_blank' you can just use class='target-blank', if the browser does not support javascript it will not open in a new window but the link will still work - and we have our valid xhtml.

Resources

Friday, August 21, 2009

Ajax error handling with ruby on rails and jquery

This sample is just a slight modification of this post 'Handling AJAX errors and displaying friendly error messages to users'. Basically I wanted to maintain the existing rails error handling for non-ajax pages and then have good handling for errors in both development and production mode; i.e. get errors in the browser when in development mode and show a nice message when in production mode.

Modify /app/controllers/application.rb; add the rescue_from macro and the handler_exception method


Then add a global javascript method for presenting the errors; most likely in application.js

Then a sample usage, jquery making an ajax post to a rails controller action

in development mode the error message is returned in an easier to read view in the firebug console and an alert message is presented that has a truncated version of the error

dev mode

in production mode just a friendly error message.

production mode

Resources

Monday, February 16, 2009

use jquery to disable a button when clicked

jquery is such a great javascript library, the more I use it the more I like it



NOTE: the above code snippets are untested - cut, pasted and modified from real code that was tested (and worked!)

 
Custom Search
< ... back