Check text field for any values

Discussion in 'JavaScript' started by auchampach, Oct 31, 2008.

  1. #1
    Hi all, I am trying to validate weather or not a text box contains any text or not. I am pretty certain my javascript works, except I don't think my javascript is able to see my input field. Any ideas why it can't read it? My other js works.



    //Javascript
    function CharCount()
    {
    valid = true;
    if (document.uspworkphn4.value == "" )
    {
    valid = false;
    }
    else
    {
    alert('The Extension field is meant for non-Direct Dial branches only. \n If you have a Direct Dial (10-digit) number that rings directy \nto your phone, please leave the extension number blank.');
    }
    }

    //HTML
    <input type="input" id="uspworkphn4" name="uspworkphn4" onblur="CharCount();" OnKeypress="return isNumberKey(event)" value="#uspworkphn4#" size="5" maxlength="10" />
    Edit/Delete Message
     
    auchampach, Oct 31, 2008 IP
  2. Bind

    Bind Peon

    Messages:
    70
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you need to use the form name in the arguement:

    
    if (document._FORM_NAME_uspworkphn4.value == "" )
    
    
    Code (markup):
     
    Bind, Oct 31, 2008 IP
  3. auchampach

    auchampach Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Actually, I found that this did work for me:

    if (document.getElementByID("uspworkphn4").value == "")
     
    auchampach, Oct 31, 2008 IP
  4. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #4
    if you really want to get longivity out of this...
    if (document.getElementByID("uspworkphn4").getAttribute("value").length == 0)
     
    dimitar christoff, Oct 31, 2008 IP