471,305 Members | 1,051 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,305 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 1342
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Pemburger | last post: by
1 post views Thread by Brad Hehe | last post: by
2 posts views Thread by qsweetbee | last post: by
7 posts views Thread by phillip.s.powell | last post: by
36 posts views Thread by aljamala | last post: by
2 posts views Thread by Joey | last post: by
reply views Thread by rosydwin | last post: by

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.