Welcome to WebmasterWorld Guest from 54.167.110.211

Forum Moderators: open

Message Too Old, No Replies

jquery select text in input field on page load

attempting to select the text inside an input text field on page load

     
2:13 pm on Jul 7, 2011 (gmt 0)

New User

5+ Year Member

joined:May 12, 2009
posts: 21
votes: 0


My input field is this:

<input class="grpsearch" type="text" id="grpinputString" name="search" value="Search for a group..." autocomplete="off" />

My javascript:

<script>
$(document).ready(function() {
$("#grpinputString").focus(function(){
$("#grpinputString").select();
});
});
</script>

I've tried a great many ways to make this work but the text inside the input field just won't select on page load.
2:25 pm on July 7, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:July 8, 2010
posts:114
votes: 0



<script>
$(document).ready(function() {
$("#grpinputString").select();
});
</script>


Should work, it should put the cursor in an input field with the ID "grpinputString" when the page loads....

What you where doing was binding a function to the focus EVENT (ie. when someone puts his/her cursor in the input field, it would call ' $("#grpinputString").select(); '
2:41 pm on July 7, 2011 (gmt 0)

New User

5+ Year Member

joined:May 12, 2009
posts: 21
votes: 0


That worked, but it only works if I load the individual page. On my site I load this page in an iframe with a jquery lightbox plugin. When the plugin loads it, it still doesn't select the field. Is there any reason why this is happening or a workaround for it?
3:18 pm on July 7, 2011 (gmt 0)

New User

5+ Year Member

joined:May 12, 2009
posts: 21
votes: 0


Got it to work, apparently I needed to focus the input field before selecting it for it to work in an iframe. Thank you for all the help.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members