PDA

View Full Version : Attributes and a Javascript validation script


chucklasker
06-30-06, 05:04 PM
I want to use a Javascript checkform validation script to validate a product page's attributes. I'm hard-coding the form completely, and it has [] characters that are screwing up the Javascript.

Here is some of the attribute code:

<INPUT TYPE="hidden" NAME="AttributeCode[3]" VALUE="PartInfo">
Middle Name:
<INPUT TYPE = "text" NAME = "AttributeValue[3]" VALUE = "" SIZE = 40>


Here is the onsubmit script:

<INPUT TYPE="submit" VALUE="Add To Basket" onClick="YY_checkform('form1','Attribute[3]','#q','0','Please enter your Middle Name.');return document.MM_returnValue">

The problem is, the brackets kill the javascript. Any idea how I can get around that?

Note - I'm using more sophisticated validation checks than the Miva server-side checks, which is why I'm using Javascript.

Vic - WolfPaw Computers
06-30-06, 07:12 PM
Chuck,

Escape the brackets with \ in your javascript. AttributeName'\['0'\]'

chucklasker
06-30-06, 10:32 PM
Chuck,

Escape the brackets with \ in your javascript. AttributeName'\['0'\]'

Thanks, Vic. We tried every combination we could think of in using the slash as the escape. None work. I think part of the problem is the checkform script has code in it that has it's own [2] type stuff... Maybe I need a different checkform validation script...

Vic - WolfPaw Computers
06-30-06, 11:30 PM
You might be able to create an array with AttributeName in javascript and pass the input name value as a string. There you should be able to append the brackets and array position.