473,246 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

create an array of field to test if they are null

is there a function that get the name of the first input field of the
current form ?
in my example below I want create an array of form field name and in the
onsubmit assign all element's name to create a simple iteration to test if
some elements in my array, that must be required, are null:
something like function verify(array of string) and in onsubmit something
like return onsubmit(field1,field2,field3....)

<HTML>
<HEAD>
<TITLE>Confirm Dialog Test</title>

<SCRIPT LANGUAGE=JAVASCRIPT>
function verify()
{
if(document.forms[0].GetElementById[0].value=="")
{
alert("Please enter a value in the field");
return false;
}
else{
return true;
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM onSubmit="return verify()">
Name: <INPUT TYPE=TEXT NAME="myName"><BR>
<INPUT TYPE=SUBMIT VALUE="Submit">
</FORM>
</BODY>
</HTML>
Jul 23 '05 #1
1 1612
On Wed, 06 Oct 2004 14:13:21 GMT, SAN CAZIANO <al**********@tin.it> wrote:
is there a function that get the name of the first input field of the
current form ?
No, but you can use the elements collection to get form controls by
ordinal number:

formObj.elements[0] // first element
formObj.elements[1] // second, etc...

and from that you can get the name or id:

formObj.elements[0].name or .id

However, that isn't really necessary for what you (seem to) want to do.
in my example below I want create an array of form field name and in the
onsubmit assign all element's name to create a simple iteration to test
if some elements in my array, that must be required, are null:
something like function verify(array of string) and in onsubmit
something like return onsubmit(field1,field2,field3....)
If you use

<form ... onsubmit="return verify(this)">

function verify(form) {

you can use the elements collection, as I demonstrated above.

To check that the first control has a value:

function verify(form) {
if('' == form.elements[0].value) {
alert('Please enter a value');
return false;
}
}

If you want to actually use the name of the control, substitute the number
with a string containing that name:

if('' == form.elements['myName'].value) {

[snip]
<SCRIPT LANGUAGE=JAVASCRIPT>


Don't use the language attribute any more. Not only is it deprecated, but
the required type attribute makes it redundant.

<script type="text/javascript">

[snip]

I hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mountain Bikn' Guy | last post by:
How would I do this? public sealed class UtilityClass { public static MyObject Object1;//see note below about importance of static object names in this class public static MyObject Object2;...
3
by: John Haigh | last post by:
I have the need to create an array of objects. Now this sound fairly trivial but I can't figure this out. I have one class called PostingObjectService that has a method GetPostings where the...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
2
by: Mikhail Teterin | last post by:
Hello! I'm going through the fields of a class one at a time and need to handle differently depending on whether they are arrays or scalars. What's the right way to make the distinction? The...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.