JohnHind
asked on
how to test if control exists on form
In vbscript, when the user submits a form, I want to check a value has been put into a control, but in some cases the control might not exist.
I want to do something like:
if IsNull(document.myForm.edt Username.v alue) = true then....
but it will raise an error if the control does not exist. Any ideas ?
TIA
John
I want to do something like:
if IsNull(document.myForm.edt
but it will raise an error if the control does not exist. Any ideas ?
TIA
John
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
jitganguly
I need to detect if the actual control itself exists, not if it has a value.
thanks
John
I need to detect if the actual control itself exists, not if it has a value.
thanks
John
ASKER
you didn't answer the question exactly, but you were the only person to answer, so you get the points !
John
John
function IsBlank(strFieldName,strMe
{
if(eval("document.admin." + strFieldName + ".value == ''"))
{
alert(strMessage);
eval("document.admin." + strFieldName + ".focus()");
return false;
}
}
<form method=post action="Admin.asp" name="admin" onsubmit="return validatePassword()">
<tr>
<td>Server</td>
<td><input type=text name="dbserver" value="<%=dbserver%>" <%=sRead%> onblur="return IsBlank('dbserver','Server
</tr>
<tr>
<td>Database</td>
<td><input type=text name="dbdatabase" value="<%=dbdatabase%>" <%=sRead%> onblur="return IsBlank('dbdatabase','Data
</tr>
<tr>
<td>Database User Id</td>
<td><input type=text name="dbuser" value="<%=dbuser%>" <%=sRead%> onblur="return IsBlank('dbuser','Database
For each columns/fields in html form I pass form field name and error message on onblur to a javascript function and that function does the validations
You can even do it on form onsubmit. I have a separate function on onsubmit of this thats why I do it on onblur