Find jobs - Submit articles - Air Force 1 Shoes - Find jobs - Credit Card Consolidation

PDA

View Full Version : Check text field for any values


auchampach
Oct 31st 2008, 6:36 am
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

Bind
Oct 31st 2008, 8:39 am
you need to use the form name in the arguement:


if (document._FORM_NAME_uspworkphn4.value == "" )

auchampach
Oct 31st 2008, 8:42 am
Actually, I found that this did work for me:

if (document.getElementByID("uspworkphn4").value == "")

dimitar christoff
Oct 31st 2008, 11:03 am
Actually, I found that this did work for me:

if (document.getElementByID("uspworkphn4").value == "")
if you really want to get longivity out of this...
if (document.getElementByID("uspworkphn4").getAttribute("value").length == 0)