Solved

how to test if control exists on form

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Time/Date Query 11 43
Summernote required 3 190
Writing comments on <p></P> or paragraph 2 19
Adding Row and Cell on a table 14 25
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/…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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