homepage Welcome to WebmasterWorld Guest from 54.205.254.108
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

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




msg:4336354
 2:13 pm on Jul 7, 2011 (gmt 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.

 

lostdreamer




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

jaruba




msg:4336380
 2:41 pm on Jul 7, 2011 (gmt 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?

jaruba




msg:4336401
 3:18 pm on Jul 7, 2011 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved