Solved

how to test if control exists on form

Posted on 2002-05-09
4
189 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Classic ASP, Search Recordset on pick list change 1 52
format nvarchar field as mm/dd/yyyy 4 61
Error viewing ASP page 12 148
Error in query expression 3 35
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/…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now