Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to test if control exists on form

Posted on 2002-05-09
4
Medium Priority
?
195 Views
Last Modified: 2008-02-01
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.edtUsername.value) = true then....

but it will raise an error if the control does not exist. Any ideas ?

TIA
John
0
Comment
Question by:JohnHind
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:jitganguly
ID: 6999848
Do it like this

function IsBlank(strFieldName,strMessage)
{
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 Name Cannot be blanks');"></td>
</tr>
<tr>
<td>Database</td>
<td><input type=text name="dbdatabase" value="<%=dbdatabase%>" <%=sRead%> onblur="return IsBlank('dbdatabase','Database Name Cannot be blanks');"></td>
</tr>
<tr>
<td>Database User Id</td>
<td><input type=text name="dbuser" value="<%=dbuser%>" <%=sRead%> onblur="return IsBlank('dbuser','Database User ID Cannot be blanks');"></td>

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
0
 
LVL 20

Accepted Solution

by:
jitganguly earned 300 total points
ID: 6999852
BTW - this is Javascript. I use Javascript on client side to make it work on NN also
0
 

Author Comment

by:JohnHind
ID: 7001910
jitganguly

I need to detect if the actual control itself exists, not if it has a value.

thanks
John
0
 

Author Comment

by:JohnHind
ID: 7029161
you didn't answer the question exactly, but you were the only person to answer, so you get the points !

John
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question