Welcome to WebmasterWorld Guest from 54.205.251.179

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)

5+ Year Member



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 Jul 7, 2011 (gmt 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 Jul 7, 2011 (gmt 0)

5+ Year Member



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 Jul 7, 2011 (gmt 0)

5+ Year Member



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.