Forum Moderators: open

Message Too Old, No Replies

Instantly add AND remove attribute from element?

Instantly allow Firefox to add or remove spellcheck to input element?

         

JAB Creations

5:22 pm on Oct 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Firefox 2 supports spellchecking...
[developer.mozilla.org...]

What I would like to do is instantly give a visitor the ability to toggle (both add and remove) the spellcheck attribute to an input element (input, textarea, etc).

Some people such as myself may prefer to simply add syntax to the dictionary. Others may find the spellchecker to be useful in half the circumstances they will encounter it. My goal is to let them decide without having to directly change anything in their browser (but of course the page itself instead). This is intended to be a per page script so I'm not looking to use cookies or anything to remember the user's preferences. I'm also going to use serverside code to avoid serving the attribute to anything that does not support it (basically anything but Gecko and especially validators!) plus I plan on having it served based on a user's preference when registered.

I'm still trying to learn how to construct JavaScript and with a lot of awesome coders here I at least have some ideas of what syntax may be used (though feel free to point out why I am wrong about anything that is in my initial perception please).

I know we have to target the element.
document.getElementById("null")

I figure we should make this dynamic in case we want to support multiple input/textarea forms. I have a bit of trouble with dynamic JavaScript.

I figure setting the attribute and value will probably look like...
setAttribute("spellcheck", false);
and...
setAttribute("spellcheck", true);

- John

[edited by: JAB_Creations at 5:24 pm (utc) on Oct. 30, 2006]

Fotiman

4:57 pm on Oct 31, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Without having given this much thought, my initial thought is that this should be fairly easy. I'm thinking you'd need a checkbox to toggle it on and off. You'd need an onclick handler for the checkbox that would add spellcheck="true" or spellcheck="false" to the <body> element, depending on the state of the button. The hardest part would be testing for browser support of this feature. I suppose you could sniff for the specific browser version, but that approach has proven itself to be a bad thing.

Good luck.