Showing posts with label webdev. Show all posts
Showing posts with label webdev. Show all posts

Thursday, 18 January 2007

Interesting book on website accessibility

http://joeclark.org/book/

Found while doing a search on a problem I've been having with a page
containing two forms, and they both have an input textbox with
tabindex="1".

The problem: One form on the page contains a search box, and the other
is a form for posting comments. Now what happens is when I'm in the
comment form, at the first textbox, when I press tab to get to the
next textbox, I end up going to the search box instead, I think
because it has tabindex="1" also.

And his advice is:

http://joeclark.org/book/sashay/serialization/Chapter12.html

"Of course, if there's a search field on every page but the content of
the page in question consists of a separate form not duplicated
elsewhere, then that big form is what takes precedence."

Though there's no advice on what to do about the conflicting tabindex
values. Maybe I should just experiment and see how it works out. Hmm..
interesting idea.

I like what he has to say about "Reset" buttons:

"In general, Reset buttons are a miserable idea. Real-world visitors
are quite likely to hit the button by accident and wipe out everything
they have entered in the form. Web developers seem to include Reset
buttons because HTML makes it easy. I've been online since before
there even was a Web and I can tell you categorically that I have
never once found a Reset button that truly needed to be there."

Friday, 5 January 2007

Preventing a page from reloading when using onClick event in a HREF

The hyperlink is often used instead of a button to run a javascript method using the onClick() event of a link with a value of "#"

<a href="#" onclick="someMethod();">This Does Something</a>

However this also reloads the page, which may result in loss of some changes performed by someMethod(). For example, if someMethod() changes the display of page elements -- a page reload will result in the page looking like it was *before* someMethod() was called.

To prevent this, it's good practice to return false to the onclick event, similar to the way we return false to onsubmit event in a form, where we don't want the form to submit.
so we either:

1. Modify someMethod() to return a value of false and change our HREF to:
<a href="#" onclick="return someMethod();">This Does Something</a>

2. Or add a return false; after calling someMethod(), like so:
<a href="#" onclick="someMethod(); return false;">This Does Something</a>