469,343 Members | 5,373 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

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 1198
gits
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>
  6.  
  7. <input type="text" name="test" onblur="do_blur(this);"/>
  8.  
kind regards
Sep 10 '07 #2
iam_clint
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>
  22.  
Gits your version didn't work in IE for me because there was no delay between resetting the value.
Sep 10 '07 #3
gits
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
gits
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.