Hi there,
I'm stuck on a validation function for a form and I cannot figure out what
the problem is. The page is in ASP. Any ideas?
The function being called is:
<script language="JavaS cript" type="text/javascript">
function checkform ( form )
{
if (form.txtDate.v alue == "")
{
alert( "Si us plau, seleccioneu la data del festiu sol·licitat per
l'usuari" );
form.txtDate.fo cus();
return false;
}
if (form.CboType.v alue == "")
{
alert( "Si us plau, seleccioneu el tipus de festiu sol·licitat per
l'usuari" );
form.CboType.fo cus();
return false;
}
if(!isDate(form .txtDate.value) )
{
alert("Format de data invàlida (dd-mm-aaaa)");
form.txtDate.fo cus();
return false;
}
if ((form.txtDetai ls.value=="") && (form.CboType.v alue==7))
{
alert( "Si us plau, introdui el motiu de la sol·licitud" );
form.txtDetails .focus();
return false;
}
if ((form.txtDetai ls.value=="") && (form.CboType.v alue==8))
{
alert( "Si us plau, introdui el motiu de la sol·licitud" );
form.txtDetails .focus();
return false;
}
return true;
}
</SCRIPT>
The function is called by:
<form method="post" name="frmMain" action="process .asp" onsubmit="retur n
checkform(this) ;" >
<table border="1" width="25%" id="table1" cellspacing="0" >
<tr>
<td>
<div align="center">
<table border="0" width="89%" id="table2" cellspacing="0"
cellpadding="0" >
<tr>
<td width="19%">&nb sp;</td>
<td width="68%"><IN PUT TYPE="hidden" NAME="txtUser" value="<%=
Session("UseID" ) %>"></td>
</tr>
<tr>
<td colspan="2">
<img border="0" src="images/blank1pix.gif" width="1" height="1"></td>
</tr>
<tr>
<td width="19%"><fo nt class="welcome" >Data:</font></td>
<td width="68%">
<INPUT TYPE="text" NAME="txtDate" class="Days" STYLE="width: 140px"
readonly>
<A HREF="#" onClick="if(oDP )oDP.open(frmMa in.txtDate);ret urn false;">
<IMG SRC="images/calendar.gif" BORDER="0" WIDTH="16" HEIGHT="15"
ALT="Triar una data">
</A>
</td>
</tr>
<tr>
<td colspan="2">
<img border="0" src="images/blank1pix.gif" width="1" height="1"></td>
</tr>
<tr>
<td width="19%"><fo nt class="welcome" >Tipus:</font></td>
<td width="68%">
<select size="1" name="CboType" class="Days" STYLE="width: 170px">
<option> </option>
<option value ="1">Dia de vacances </option>
<option value ="6">Mig dia de vacances</option>
<option value ="7">Dia de permis </option>
<option value ="8">Mig dia de permis </option>
</select></td>
</tr>
<tr>
<td width="87%" colspan="2">
<img border="0" src="images/blank1pix.gif" width="1" height="1"></td>
</tr>
<tr>
<td width="19%" valign="top"><f ont
class="Welcome" >Detalls:</font></td>
<td width="68%">
<INPUT TYPE="text" NAME="txtDetail s" class="Days" STYLE="width: 170;
height:65"></td>
</tr>
<tr>
<td colspan="2">&nb sp;</td>
</tr>
<tr>
<td width="19%">&nb sp;</td>
<td align="right" width="68%">
<input type="reset" value="Començar " name="B2" class="button"> <input
type="submit" value="Enviar" name="B1" class="button"> </td>
</tr>
<tr>
<td width="19%">&nb sp;</td>
<td align="right" width="68%">
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</form>
The last 2 checks before the end of the script are not working. I started
having them as one unique check like:
if ((form.txtDetai ls.value=="") && (form.CboType.v alue==7 ||
form.CboType.va lue==8))
{
alert( "Si us plau, introdui el motiu de la sol·licitud" );
form.txtDetails .focus();
return false;
}
Still no luck.
I don't know if it is a syntax problem but it ain't working.
Thanks in advance,
Marc 3 1644
Marc Llenas wrote: Hi there,
I'm stuck on a validation function for a form and I cannot figure out what the problem is. The page is in ASP. Any ideas?
if (.... (form.CboType.v alue==7))
This may not be only problem, but the universal way to read a select
element is by indexing its options array with its selectedIndex
property:
form.CboType.op tions[ form.CboType.se lectedIndex ].value
--
S.C.
Marc Llenas wrote: Hi there,
I'm stuck on a validation function for a form and I cannot figure out what the problem is. The page is in ASP. Any ideas?
The function being called is:
When posting code, manually wrap it at about 70 characters to prevent
wrapping, which otherwise introduces more errors that must be fixed
before help can be provided. <script language="JavaS cript" type="text/javascript">
The language attribute is depreciated, type is required:
<script type="text/javascript">
function checkform ( form ) { if (form.txtDate.v alue == "") { alert( "Si us plau, seleccioneu la data del festiu sol·licitat per l'usuari" );
Here is some error-inducing wrapping, more occurs elsewhere:
alert( "Si us plau, seleccioneu la data del festiu"
+ " sol·licitat per l'usuari" );
form.txtDate.fo cus(); return false; } if (form.CboType.v alue == "") { alert( "Si us plau, seleccioneu el tipus de festiu sol·licitat per l'usuari" ); form.CboType.fo cus(); return false; }
if(!isDate(form .txtDate.value) )
Leaving in this line without the code for isDate() causes an error that
must be fixed in order to make your code run. Either remove it or
include a dummy isDate().
{ alert("Format de data invàlida (dd-mm-aaaa)"); form.txtDate.fo cus(); return false; } if ((form.txtDetai ls.value=="") && (form.CboType.v alue==7))
For some browsers, the value of a select is the value of the selected
option (e.g. Firefox), but for other browsers (e.g. IE) you have to use
the selectedIndex value:
if (form.txtDetail s.value==""
&& form.CboType[form.CboType.se lectedIndex].value==7) {
{ alert( "Si us plau, introdui el motiu de la sol·licitud" ); form.txtDetails .focus(); return false; } if ((form.txtDetai ls.value=="") && (form.CboType.v alue==8)) { alert( "Si us plau, introdui el motiu de la sol·licitud" ); form.txtDetails .focus(); return false;
As you noted, these tests could be combined:
var t = form.CboType[form.CboType.se lectedIndex].value;
if ((8==t || 7==t) && "" == form.txtDetails .value){
...
} return true; } </SCRIPT>
The function is called by:
<form method="post" name="frmMain" action="process .asp" onsubmit="retur n checkform(this) ;" >
Here wrapping has caused an issue with testing your code. The script
parser sees - return - then a carriage return, followed by a statement
so a semi-colon is inserted. The return executes without doing the
checkform() bit and without an error - debugging your code is made that
much more difficult.
<form method="post" name="frmMain" action="process .asp"
onsubmit="retur n checkform(this) ;" >
[...]
<INPUT TYPE="text" NAME="txtDate" class="Days" STYLE="width: 140px" readonly> <A HREF="#" onClick="if(oDP )oDP.open(frmMa in.txtDate);ret urn false;">
What does oDP do? Presumably it creates a pop-up with a date selector -
for the sake of testing, why not hard-code a valid value in the onclick,
or in the readonly txtDate form control?
Your reference to the form uses 'frmMain' as a global variable, that
will work only in IE:
<A HREF="#" onClick="
if(oDP)oDP.open (document.forms['frmMain'].elements['txtDate']);
return false;
">
Many would say that you should use the image element with a pointer
cursor and remove the A element. Or better, use a button and then the
reference to the form becomes shorter:
<input type="button" value="Calendar " onClick="
if(oDP)oDP.open (this.form.elem ents['txtDate']);
return false;
">
[...]
--
Rob
Woa!, thanks a bunch Rob,
This is probably the most in-dept review of a piece of code I've ever seen.
Will modify the code as per your suggestions. Thanks a million.
Marc
"RobG" <rg***@iinet.ne t.au> escribió en el mensaje
news:vu******** *********@news. optus.net.au... Marc Llenas wrote: Hi there,
I'm stuck on a validation function for a form and I cannot figure out what the problem is. The page is in ASP. Any ideas?
The function being called is:
When posting code, manually wrap it at about 70 characters to prevent wrapping, which otherwise introduces more errors that must be fixed before help can be provided.
<script language="JavaS cript" type="text/javascript">
The language attribute is depreciated, type is required:
<script type="text/javascript">
function checkform ( form ) { if (form.txtDate.v alue == "") { alert( "Si us plau, seleccioneu la data del festiu sol·licitat per l'usuari" );
Here is some error-inducing wrapping, more occurs elsewhere:
alert( "Si us plau, seleccioneu la data del festiu" + " sol·licitat per l'usuari" );
form.txtDate.fo cus(); return false; } if (form.CboType.v alue == "") { alert( "Si us plau, seleccioneu el tipus de festiu sol·licitat per l'usuari" ); form.CboType.fo cus(); return false; }
if(!isDate(form .txtDate.value) )
Leaving in this line without the code for isDate() causes an error that must be fixed in order to make your code run. Either remove it or include a dummy isDate().
{ alert("Format de data invàlida (dd-mm-aaaa)"); form.txtDate.fo cus(); return false; } if ((form.txtDetai ls.value=="") && (form.CboType.v alue==7))
For some browsers, the value of a select is the value of the selected option (e.g. Firefox), but for other browsers (e.g. IE) you have to use the selectedIndex value:
if (form.txtDetail s.value=="" && form.CboType[form.CboType.se lectedIndex].value==7) {
{ alert( "Si us plau, introdui el motiu de la sol·licitud" ); form.txtDetails .focus(); return false; } if ((form.txtDetai ls.value=="") && (form.CboType.v alue==8)) { alert( "Si us plau, introdui el motiu de la sol·licitud" ); form.txtDetails .focus(); return false;
As you noted, these tests could be combined:
var t = form.CboType[form.CboType.se lectedIndex].value; if ((8==t || 7==t) && "" == form.txtDetails .value){ ...
} return true; } </SCRIPT>
The function is called by:
<form method="post" name="frmMain" action="process .asp" onsubmit="retur n checkform(this) ;" >
Here wrapping has caused an issue with testing your code. The script parser sees - return - then a carriage return, followed by a statement so a semi-colon is inserted. The return executes without doing the checkform() bit and without an error - debugging your code is made that much more difficult.
<form method="post" name="frmMain" action="process .asp" onsubmit="retur n checkform(this) ;" >
[...]
<INPUT TYPE="text" NAME="txtDate" class="Days" STYLE="width: 140px" readonly> <A HREF="#" onClick="if(oDP )oDP.open(frmMa in.txtDate);ret urn false;">
What does oDP do? Presumably it creates a pop-up with a date selector - for the sake of testing, why not hard-code a valid value in the onclick, or in the readonly txtDate form control?
Your reference to the form uses 'frmMain' as a global variable, that will work only in IE:
<A HREF="#" onClick=" if(oDP)oDP.open (document.forms['frmMain'].elements['txtDate']); return false; ">
Many would say that you should use the image element with a pointer cursor and remove the A element. Or better, use a button and then the reference to the form becomes shorter:
<input type="button" value="Calendar " onClick=" if(oDP)oDP.open (this.form.elem ents['txtDate']); return false; ">
[...]
-- Rob This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Brian |
last post by:
I am having alot of trouble getting a XML document validated with a
schema.
I got a sample document and schema off of w3schools.com, which passed
an online xml validator:
http://tools.decisionsoft.com/schemaValidate.html. I cannot, however,
get them validated programmatically.
The documents are:
|
by: AnnMarie |
last post by:
<script language="JavaScript" type="text/javascript">
<!--
function validate(theForm)
{
var validity = true; // assume valid
if(frmComments.name.value=='' && validity == true)
{
alert('Your full name is required. Please enter your full name!');
validity = false;
frmComments.name.focus();
|
by: glenn |
last post by:
I have a COM Server that I've written based on information from the book
..NET and COM / the complete Interop Guide. I have gotten the project to
compile and I've located the regasm.exe program that I was suppose to run
against my dll in order to generate a TLB file for the purposes of importing
the COM object into other programming lanugages such as Delphi.
However, when I try to import the type library into Delphi which I have done...
|
by: Chris Nunciato |
last post by:
I'm working on a simple Web application that uses a wizard-style
data-entry paradigm (seven "pages", using "next" and "previous"
buttons), and I'm having a problem with the validation.
On page one (which is actually just a Panel control), when the user
clicks "next," I hide Panel_1 and show Panel_2. However, the
RequiredFieldValidator controls in Panel_1 only appear to work with
Internet Explorer on Windows; when I click "next" using...
|
by: ninja_kornjaca |
last post by:
Hello,
I'm having a pretty strange problem and I'd appreciate if anyone could help
me with it.
I'm having a custom error page on my IIS. Specifically, I've written my own
ASP (classic ASP) error page for "404 Not Found" error. It does some work in
database (via. ADO), and the redirects user to another page. No big deal.
And it worked just fine when all my pages on my website were pure old ASP.
| |
by: Tarun Upadhyaya |
last post by:
Hi,
I am facing strange problem
I read Scott mitchell's article about ASP.NET and javascript at
http://www.msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/clientsidescript.asp
where he has talked about creating a base class for displaying alerts and
confirms after and before postbacks respectively.
I used that Base class to inherit on of my code behind classes and and i
|
by: Code Rodent |
last post by:
Hi there,
Please please could someone shed some like on a problem that I'm having
using a combination of Wizards, ValidationGroups and ValidationSummary
controls. What I want to do is to have a wizard that will take me through
several steps, and at each step validate input data using
RequiredFieldValidators etc. displaying any errors in a Validation Summary.
The problem that I have is that I cannot seem to have a ValidationSummary...
|
by: kbrolin65 |
last post by:
Hi, folks. Please be patient, as I am not a programmer. But I wasn't
sure where to turn for advice except for a programming discussion
group. I am an intermediate PC user--fairly knowledgeable, but with a
problem that even Web site technical support hasn't been able to solve.
Here's a problem I've never encountered before wwithout a
popup-blocker: inability to connect to Streamaudio.com , a multimedia
site with links to live radio...
|
by: Einstein30000 |
last post by:
Hi,
in one of my php-scripts is the following query (with an already open
db-connection):
$q = "INSERT INTO main (name, img, descr, from, size, format, cat,
host, link, date) VALUES ('$name', '$img', '$descr', '$user', '$size',
'$format', '$cat', '$host', '$link', '$date')" or die(mysql_error());
And when the query gets executed i get back the following error:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |