Question

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!

Was it helpful?

Solution

 $(function() { 
  $('input[type=text]').focus(function() {
     $(this).trigger('select');
  });
});

You can test it here

OTHER TIPS

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top