472,978 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

help with syntax in form validation

Hello,

I am trying to make use of the following:

function checkIt(){
if (document.PRODADD.AttributeValue[1].value == "") { //validate month
select
alert("Please select an option!");
document.myForm.ExpMonth.focus();
return false;

}
if (document.PRODADD.AttributeValue[41].value == "") { //validate year
select
alert("Please select an option");
document.myForm.ExpYear.focus();
return false;
}
return true;
}
And then later of course is:

<FORM NAME="PRODADD" METHOD="post" ACTION="../prodadd.asp" onsubmit="return
checkIt();">

The first problem is that javascript does not seem to like

AttributeValue[1]
AttributeValue[41]

Those are the select names in the form as in:

<SELECT NAME="AttributeValue[41]">

The [ and ] characters seem to be causing a choke. If I remove them from
the javascript function and the select names it works. If I put them back
I get this error:

document.PRODADD.AttributeValue.1 is null or not an object.

I *have* to keep those brackets in the select name area of the form. I
assume it is a matter of changing the syntax up in the function to properly
"see" them?

Problem #2 is that even when the function works the form submits as soon as
you OK the alert popup. How do I halt that?

Thank you very much.
May 4 '06 #1
4 1403
Oops sorry. I figured out part 2, keeping the form from submitting after
the alert. My fault there, forgot to update the function here:

document.myForm.ExpMonth.focus()

and here:

document.myForm.ExpYear.focus()

Those were holdovers from the original I found online.

But the problem with the [ ] causing a choke still stands.
Hello,

I am trying to make use of the following:

function checkIt(){
if (document.PRODADD.AttributeValue[1].value == "") { //validate month
select
alert("Please select an option!");
document.myForm.ExpMonth.focus();
return false;

}
if (document.PRODADD.AttributeValue[41].value == "") { //validate year
select
alert("Please select an option");
document.myForm.ExpYear.focus();
return false;
}
return true;
}
And then later of course is:

<FORM NAME="PRODADD" METHOD="post" ACTION="../prodadd.asp"
<onsubmit="return
checkIt();">

The first problem is that javascript does not seem to like

AttributeValue[1]
AttributeValue[41]

Those are the select names in the form as in:

<SELECT NAME="AttributeValue[41]">

The [ and ] characters seem to be causing a choke. If I remove them
from the javascript function and the select names it works. If I put
them back I get this error:

document.PRODADD.AttributeValue.1 is null or not an object.

I *have* to keep those brackets in the select name area of the form. I
assume it is a matter of changing the syntax up in the function to
properly "see" them?

Problem #2 is that even when the function works the form submits as soon
as you OK the alert popup. How do I halt that?

Thank you very much.


May 4 '06 #2
Alan Edmund said on 04/05/2006 2:53 PM AEST:
Hello,

I am trying to make use of the following:

function checkIt(){
if (document.PRODADD.AttributeValue[1].value == "") { //validate month ------------------------------------^^^^

if (document.PRODADD['AttributeValue[1]'].value == "") { ...
The way you have written it, you are looking for an array or collection
called document.PROADD.AttributeValue that has a member at index 1.

<URL;http://www.jibbering.com/faq/#FAQ4_39>

[...]

I *have* to keep those brackets in the select name area of the form. I
assume it is a matter of changing the syntax up in the function to properly
"see" them?


Yes. Read the above reference and the link below on useage of square
brackets.

<URL:http://www.jibbering.com/faq/faq_not..._brackets.html >

[...]
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>
"It is much easier for a web developer to create a site
that receives no complaints than to create a site that
doesn't warrant any."--Richard Cornford
May 4 '06 #3
RobG said on 04/05/2006 3:45 PM AEST:
Alan Edmund said on 04/05/2006 2:53 PM AEST:
Hello,

I am trying to make use of the following:

function checkIt(){ if (document.PRODADD.AttributeValue[1].value ==

--------------------------------------------------------^^^


That should of course be highlighting the [1].
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>
May 4 '06 #4
ASM
Alan Edmund a écrit :
Hello,

I am trying to make use of the following:
I prefer to use a generic way

function checkAll(myForm) {
var txt = 'You have not answered the field : ';
for(var i=0;i<myForm.length;i++) if(myForm[i].value=='') {
alert(txt+myForm[i].name);
myForm[i].focus();
return false;
}
return true;
}

<FORM NAME="PRODADD" onsubmit="return checkAll(this.form);" ... >

function checkIt(){
if (document.PRODADD.AttributeValue[1].value == "")
if (document.PRODADD['AttributeValue[1]'].value == "")
or
if (document.PRODADD.elements['AttributeValue[1]'].value == "")

{ //validate month select
alert("Please select an option!");
document.myForm.ExpMonth.focus();
return false;
} Problem #2 is that even when the function works the form submits as soon as
you OK the alert popup. How do I halt that?


the onsubmit from form returns result of your check function
if one element was not seen this function does following :
- alert (alert stops everything durind its display)
- scrolls page to the element
- return false ==>
- return = end of this function
- false = form's action disabled (it is not send)

--
Stephane Moriaux et son [moins] vieux Mac
May 4 '06 #5

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

Similar topics

9
by: Pemburger | last post by:
From: pemburger@aol.com I've tried the W3C MarkUp Validation Service for the following web page: http://www.coverscript.com The report given by W3C shows 300 plus errors? I am not able to...
1
by: Brad Hehe | last post by:
I am attempting to use XPath to query for a specific node in the sample XML I've provided below. I'm unsure of the exact XPath syntax, but I believe I need the following query to get the proper...
2
by: qsweetbee | last post by:
I have a form(fAddUsers) in my database. It is continue form for data entry. Some fields are required fields. Some are optional fields. There is 1 particular filed(TokenExpirationDate)on the form...
2
by: Paul | last post by:
Hi, I hope somebody can help me with the following. (I have tried searching for a solution on the newsgroups but nothing is quite what I need. Feel free to point me in the direction of anything...
7
by: phillip.s.powell | last post by:
Now I have another SQL query for MySQL I can't figure out!! This is overwhelming me completely and I also must have this figured out today and I can't figure it out!! UPDATE student_db.student...
36
by: aljamala | last post by:
Hi, I keep getting this warning on a page, but I do not know what the problem is...does anyone have an idea about what could be wrong? line 88 column 7 - Warning: missing </formbefore <td> it...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
3
by: Birky | last post by:
Hello, I’m hoping you can help me out with two issues I’m having with my code. I have an Access Report named Report_Project_Event_Log which I have calling a Form named “Custom_Code_lookup” which...
2
by: Joey | last post by:
Hello guys, I'm trying to learn about regular expressions. I need to be able to use an RE that can evaluate for STRINGS (or specific sequences of characters), not just occurances of characters....
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.