How to determine if a DHTML text box is empty?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Panky123
    New Member
    • Mar 2010
    • 7

    How to determine if a DHTML text box is empty?

    Provide me an If/Then statement to determine if a DHTML text box is empty and stop running code.
    I required this immediately.... i will be highly thankful!!!!!!
  • phvfl
    Recognized Expert New Member
    • Aug 2007
    • 173

    #2
    I assume that the textbox is either a textarea or standard text input box. Get a reference to the textbox using getElementById or similar and then check the value property.

    Comment

    • Panky123
      New Member
      • Mar 2010
      • 7

      #3
      I am new to this. so i requested u to give me step by step explanation..pl ease!!!!

      Comment

      • phvfl
        Recognized Expert New Member
        • Aug 2007
        • 173

        #4
        OK. Assuming that the text box is either an text input or textarea with an id of "myBox", this would mean html similar to:
        Code:
        <!-- A text input -->
        <input type="text" id="myBox" value="" />
        <!-- or for a textarea -->
        <textarea id="myBox" cols="10" rows="3"></textarea>
        You would be able to get a reference to the element by using getElementById and then check its values:
        Code:
          // Get a reference to the html element
          var textbox = document.getElementById("myBox");
        
          // Ensure that the element was found
          if(textbox !== null){
            // Check the value - i.e. the text in the box.
           if(textbox.value === ''){
              //Textbox is empty so do something
            }else{
              //Textbox is not empty so do something else.
            }
          }
        If you are just learning JavaScript then w3schools is a good reference point - it also contains information for other web technologies. The site is at www.w3schools.c om

        Comment

        • Panky123
          New Member
          • Mar 2010
          • 7

          #5
          Thank you so much for the help.I will try it out!!!

          Comment

          Working...