Welcome to WebmasterWorld Guest from 54.242.72.36

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

     

jaruba

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.

lostdreamer

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

5+ Year Member




<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(); '

jaruba

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?

jaruba

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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month