473,320 Members | 1,969 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,320 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 1418
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: 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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.