472,133 Members | 1,039 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

Moving view to start of text field

I'm having trouble with some javascript functionality.

I have a text input that can hold more characters than it can show. When the focus leaves the text field I have to show the start of the string again, instead of the end that they just typed in. I've been able to get this functionality to work in firefox, but not IE. The only thing I found that almost worked was using ranges and selecting elements 0 to 0. However, I'm doing this function in an onBlur action, so this will never leave the text box

Any ideas on how to view the start of a start of a string in a text field in an onBlur action?
Sep 10 '07 #1
5 1243
5,390 Expert Mod 4TB
hi ...

welcome to TSDN ...

have a look at the following example ... may be it helps :)

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function do_blur(obj) {
  3.     obj.value = obj.value;
  4. }
  5. </script>
  7. <input type="text" name="test" onblur="do_blur(this);"/>
kind regards
Sep 10 '07 #2
1,208 Expert 1GB
This is a piece of sample code i made for ya give it a go (works in firefox and IE)
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <script>
  3. var oldval = "";
  4. var objid;
  5. function moveStart(obj) {
  6.         oldval = obj.value;
  7.         obj.value = "";
  8.         objid = obj.id
  9.         window.setTimeout("resetVal();", 10);
  10. }
  11. function resetVal() {
  12.     document.getElementById(objid).value = oldval;
  13. }
  14. </script>
  15. <body>
  16. <input type="text" id="test" onblur="moveStart(this);">
  17. <input type="text" id="test1" onblur="moveStart(this);">
  18. <input type="text" id="test2" onblur="moveStart(this);">
  19. <input type="text" id="test3" onblur="moveStart(this);">
  20. </body>
  21. </html>
Gits your version didn't work in IE for me because there was no delay between resetting the value.
Sep 10 '07 #3
5,390 Expert Mod 4TB
heya iam_clint,

well ... you are certainly right ;) ... since i have no IE at home i cannot test it ... but the simple idea was to assign the same value to the field as the one thats actually typed in there ... and to avoid that selection and range operations which seems to be really obsolete here :) ... thank you for proofing and improving the idea ...

kind regards
Sep 10 '07 #4
Ah, thank you. The first post is what I was doing in firefox, and I figured that it wasn't working in IE because it was the same value... for some reason I didn't think to clear it out first. Not at my development computer right now, but I'm sure it will work. Thanks again!
Sep 11 '07 #5
5,390 Expert Mod 4TB
hi ...

no problem ... we are glad to help you ...post back to the forum anytime you have more questions ...

kind regards
Sep 12 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by ghanley | last post: by
6 posts views Thread by Bill44077 | last post: by
reply views Thread by mtsylvester | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.