www.webdeveloper.com
Results 1 to 7 of 7

Thread: Textbox Prepend

  1. #1
    Join Date
    Feb 2003
    Location
    Aberdeen, Washington, USA
    Posts
    1,859

    Question Textbox Prepend

    I got a quick one... I've been trying to figure it out myself but haven't been able to come up with anything that works fully.

    I want to prepend some text inside a textbox and force it at all times. I don't want the user to be able to remove the prepended text in any way but still allow them to add text after it.

    This may be more in just plain JavaScript but the rest of my project is using jQuery so I figure it would be best if the solution stayed within that. But, I'll accept anything that will work, really.

    Thanks!

  2. #2
    Join Date
    Jan 2005
    Location
    Frankfort, KY, USA
    Posts
    6,167
    Do you want it submitted with the textbox contents, or merely there to serve as a prompt for the person filling in the textbox?

  3. #3
    Join Date
    Feb 2003
    Location
    Aberdeen, Washington, USA
    Posts
    1,859
    Quote Originally Posted by KDLA View Post
    Do you want it submitted with the textbox contents, or merely there to serve as a prompt for the person filling in the textbox?

  4. #4
    Join Date
    Jan 2005
    Location
    Frankfort, KY, USA
    Posts
    6,167
    What I'd do is "fake" an inset textbox, with absolute positioning, then apply sufficient padding to prevent the person typing over the text.

    Also, I've used background images as "text" w/ padding, too.

    But, that's from my designer's perspective.

  5. #5
    Join Date
    Feb 2003
    Location
    Aberdeen, Washington, USA
    Posts
    1,859
    I wish I could do that. But the prepended text will be different all the time. I could do a background image with the GD library in PHP but I feel that would over-complicate things for this particular usage.

  6. #6
    Join Date
    Feb 2003
    Location
    Aberdeen, Washington, USA
    Posts
    1,859
    I've tried this but it doesn't work totally...
    Code:
    jQuery('.mytextbox').bind('input', function(e){
        jQuery(this).val('Test: ' + jQuery(this).val().replace('Test: ', ''));
    });
    When you delete all the text in the textbox the "Test: " part shows up a second time. Not sure why. If you can try it yourself you'll see what I mean.

    Also, that may not be the best way to do it...

  7. #7
    Join Date
    Feb 2003
    Location
    Aberdeen, Washington, USA
    Posts
    1,859
    Anyone?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles