Solved

how to test if control exists on form

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

19 Experts available now in Live!

Get 1:1 Help Now