1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

JS typeof related question

Discussion in 'JavaScript' started by afridy, Aug 28, 2013.

  1. #1
    [Hello,

    i want to check weather a text box is exisit or not using typeof.
    but i have some confusing on the syntax.

    
    <input name="empno" type="text" id="empno" size="15" />
    
    Code (markup):
    is this syntax correct?
    
    if (typeof empno=='object') {
    
    Code (markup):
    because i have some confusing weather i need rap empno in single quote.
     
    afridy, Aug 28, 2013 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    HuggyStudios, Aug 28, 2013 IP
    afridy likes this.
  3. afridy

    afridy Well-Known Member

    Messages:
    802
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    135
    #3
    afridy, Aug 28, 2013 IP
  4. JoeSimmons

    JoeSimmons Greenhorn

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #4
    You can just check if it's truthy or not.

    var empno = document.getElementById('empno');
    
    if (empno) {
      // exists
    }
    Code (markup):
     
    JoeSimmons, Aug 28, 2013 IP
  5. afridy

    afridy Well-Known Member

    Messages:
    802
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    135
    #5
    no buddy, that text box (id empno) may exist some time and some time not in the form, so i want to check weather that text box is present or not.
     
    afridy, Aug 28, 2013 IP
  6. JoeSimmons

    JoeSimmons Greenhorn

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #6
    The code that I posted will check if that element exists or not.
     
    JoeSimmons, Aug 29, 2013 IP