views:

61

answers:

4

I have an input field that was written with onfocus="this.value='' , but recently decided to change it to onfocus="this.select() . The trouble is that when I went to change it, it still clears! I searched my entire javascript library, html, everything looking for what could be causing that. Nothing is being called of the likes.

I tried clearing my cache. And I tried searching for value='' and cl(

Anyone know how I could debug this? Or at worse, override what it's doing to make it do what I want?

My code :

<input type="text" value="Enter Keyword or Co. Name" name="q" id="q" class="foobar">

I have also tried :

<input type="text" value="Enter Keyword or Co. Name" name="q" id="q" class="foobar" onfocus="this.select();">

Thanks!

A: 

Have you viewed the source and verified that your page is actually using the changed code? Sometimes I have to clear my cached version before it will pull changes. Just a thought.

Henry
Yep tried that.
Trip
A: 

http://jsfiddle.net/mzFQk/1/

HTML:

<input type="text" value="Enter Keyword or Co. Name" name="q" id="q" class="foobar" />

JavaScript:

$('#q').click(function(evt) {
   evt.preventDefault();
   this.select();
}); // make sure to attach this script to the domReady event

This code works perfectly, if you cannot get this to work in your website, then we cannot help you until you post the source code.

Moses
Yah, tried clearing the cache. Searched for things like `cl(this)`, and `value=''`
Trip
@moses `First, I would clear your cache ` lol, How are you going to clear his cache =)
Ninja Dude
I bet he can split the red sea as well
Trip
@moses, I tried that. It clears it before the jQuery kicks in. Even tried `preventDefault();` and `return false;`
Trip
GREAT SITE, jsfiddle. :D Thanks for the recommends.
Trip
+3  A: 
 $(function() { 
  $('input[type=text]').focus(function() {
     $(this).trigger('select');
  });
});

You can test it here

Ninja Dude
Thanks Avinash. This does work, I know. But something else is rendering the clear(), or value="". And it's called before jQuery or javascript, or even onfocus="" is called.
Trip
I don't think this works in Safari. :D
Trip
A: 

You're all going to hate me, but I found it. At the very end of the day, I just search for "#q", and found it.

$("#q").focus(function() {
   $("this").val() == ""
});

I deleted it with my battle ax.

Trip