Portal Home > Knowledgebase > Articles Database > JS: Clear Input Text on Focus
JS: Clear Input Text on Focus
Posted by Cmafai, 06-03-2009, 12:37 PM |
Alrighty, now that I've lured you in with what would appear to be a very simple question given the title, I dare you to figure out what the deal is with this page. I am no beginner JS-er, and I've done this exact thing many times before, but it's just not working. This means I'm either very tired and missing something obvious (likely), the script is doing something really funky (less likely), or the internet hates me and is playing with my mind (most likely).
Anywho, here's my dilemma. I have an input field:
and a clearing function:
When I click/focus on the input, nothing happens. When I change the onfocus event to "alert('blah');" it triggers fine, so it seems like its registering the event OK. So something must be messed up with my clear() function, right? WRONG! If I run clear() from the console, it executes it just as it should, and clears the input.
What the hell
The live site is here: www.screentunes.com
- Cecchi
|
Posted by Eoin_, 06-03-2009, 12:42 PM |
OK, I had a quick go, and for some reason FF didn't like the function name being "clear" - is it reserved or something?
|
Posted by Cmafai, 06-03-2009, 01:13 PM |
Ooh, five gold stars for you! Works perfectly, thank you!
I feel a bit stupid, as I considered changing the function name to see if that would make a difference, and then I never did for some reason...
Thanks again!
|
Posted by Eoin_, 06-03-2009, 01:27 PM |
No problems at all, was a lucky guess as the alert wasn't being triggered for me at all.
The $('input') didn't work for me at all by the way - I'm not familiar with that syntax?
|
Posted by Cmafai, 06-03-2009, 03:26 PM |
Its a function I made, because I'm lazy.
Just a shortcut/alias for getElementById... jQuery uses a similar more powerful version where you can get anything using any CSS selectors like:
Really nifty. Anywho, when you say it didn't work for you... does the website work at all for you? I use that function all over the place.
|
Posted by Eoin_, 06-03-2009, 04:21 PM |
Sorry, it didn't work on my test page. The site works fine for me.
|
Add to Favourites Print this Article
Also Read