Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2013
    Posts
    139
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question detect if input box contains text

    Hi,
    Below in my code I am setting a placeholder for my input boxes.
    I would like to addClass() if the text box has text on each of them?!

    Code:
    $( document ).ready(function() {
    $("#input_2_3").attr("placeholder","nature of enquiry");
    $("#input_2_4").attr("placeholder","name");
    $("#input_2_2").attr("placeholder","email");
    $("#input_2_5").attr("placeholder","contact no.");
    $("#input_3_1").attr("placeholder","email");
    });

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    one specific class, or unique classes? also at what point would you want this to happen? if you do it on dom ready as soon as you show the form, then obviously the inputs will be empty

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Quote Originally Posted by DanInMa View Post
    if you do it on dom ready as soon as you show the form, then obviously the inputs will be empty
    If the textboxes have default value set in the markup, then they will not be empty.

    Btw, jarv81178, why are you setting the placeholder using js? If the placeholder text are static, why not just put them directly in the <input> markup?


  •  

    Posting Permissions

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