I have two input text fields. One is for entering the title of the article and one is for the permalink of the article. What I’m wanting to do is have the permalink field disabled until text is inserted into the title field and when the user takes focus out of the title field then it runs a custom regex to replace spaces with hyphens and lowercases any uppercase letters.
<input type="text" id="title" name"title" />
<input type="text" id="permalink" name="permalink" />
It’s real easy with jQuery…
jsFiddle.
If you don’t have jQuery but only need to support standards-compliant modern browsers, it’d be…
jsFiddle.
If you didn’t have jQuery and had to support our old IE friends, it’d look like…
jsFiddle.
Note that the old fallback for event registration is to assign the
on*property. This will overwrite any previous property assigned there.If you really wanted to register multiple events for these ancient browsers, you’d modify the property assignment to use a custom handler which registered and then triggered multiple events when required.