radio element.type undefined

P

Pasquale

I am using the JS and HTML code below to check that required fields are
completed for attributes of a product. The first attribute is a select
menu and the second is a radio set. My JS goes through fine and detects
if the select menu isn't selected with a value, but I keep getting
'undefined' for the radio element type. I've almost pulled out half a
head of hair wondering why. Any experienced eyes see something I don't?

Thanks,
Pasquale

JS code:

var submitcntprod = 0;
function SubmitChkProd (formobj) {
var attrcount = formobj.elements['Product_Attribute_Count'].value;
if (submitcntprod == 0) {
if (attrcount > 0) {
for (i = 1; i <= attrcount; i++) {
var eleprompt = 'Product_Attributes['+i+']:code';
var elepromptval = formobj.elements[eleprompt].value;
var ele = 'Product_Attributes['+i+']:value';
var eleobj = formobj.elements[ele];
var eleobjtype = eleobj.type;
alert(i);
alert(elepromptval);
alert(ele+' ele');
alert(eleobj+' eleobj');
alert(eleobjtype+' eleobjtype');
if (eleobjtype == "radio") {
var radobjlen = eleobj.length;
var radnotchkd = 0;
for (j = 0; j < radiolen; j++) {
var radeleobj = formobj.elements[ele][j];
var item = radeleobj.checked;
if (item == false) {
radnotchkd++;
}
}
if (radnotchkd == radobjlen) {
alert("'"+elepromptval+"' is a required field.\n\nPlease complete
this field and any other required fields.");
return false;
break;
}
} else if (eleobjtype.indexOf("select") != -1) {
var selectitem = eleobj.options[eleobj.selectedIndex].value;
if (selectitem == "" || selectitem == "null") {
alert("'"+elepromptval+"' is a required field.\n\nPlease complete
this field and any other required fields.");
return false;
break;
}
}
}
}
submitcntprod++;
return true;
} else {
alert('This form has already been submitted. Please wait...');
return false;
}
}


HTML code:

<form name="prodattr" method="post" action="http://www.site.com"
onSubmit="return SubmitChkProd(this)">
<table border=0>
<input type="hidden" name="Product_Attributes[1]:code" value="Size">

<tr>
<td align="left" valign="top">
<font face="Arial, Helvetica" size="-1">
<b>Size:</b>
</font>
</td>
<td align="left" valign="top">
<font face="Arial, Helvetica" size="-1">
<select name="Product_Attributes[1]:value">
<option value="null" selected>&lt;Select Size&gt;</option>
<option value="XS-S">XS/S 4.5"-6.25"</option>
<option value="M">M 6.5"-7.5"</option>
<option value="L-XL">L/XL 7.75"-10"</option>

</select>
</font>
</td>
</tr>
<input type="hidden" name="Product_Attributes[2]:code" value="Color">
<tr>
<td align="left" valign="top">
<font face="Arial, Helvetica" size="-1">
<b>Color:</b>
</font>
</td>
<td align="left" valign="top">
<table border = 0>
<tr><td valign = "middle">
<input type="radio" name="Product_Attributes[2]:value" value="Red">
</td><td valign = "middle">

<font face="Arial, Helvetica" size="-1">
Red
</font>
</td></tr>
<tr><td valign = "middle">
<input type="radio" name="Product_Attributes[2]:value" value="Blue">
</td><td valign = "middle">
<font face="Arial, Helvetica" size="-1">
Blue
</font>
</td></tr>
<tr><td valign = "middle">
<input type="radio" name="Product_Attributes[2]:value" value="Black">
</td><td valign = "middle">
<font face="Arial, Helvetica" size="-1">
Black
</font>

</td></tr>
</table>
</td>
</tr>
<input type="hidden" name="Product_Attribute_Count" value="2">
<tr><td>&nbsp;</td></tr>
<tr><td align="left" valign="middle">
<font face="Arial, Helvetica" size="-1">
Quantity:
<input type="text" name="Quantity" value=1 size=4 />
<input type="submit" value="Add To Basket">
</font>
</td></tr>
</table>
</form>
 
L

Lasse Reichstein Nielsen

Jim Land said:
<input type="radio" name="Product_Attributes[2]:value" value="Black">

Poor choice of name for this element. In particular, I question your use
of [] and :

It does look odd, but it might be needed for some server side
processor.
Here's what HTML4.0 says:

Attribute values of type ID and NAME must begin with a letter in the
range A-Z or a-z and may be followed by letters (A-Za-z), digits (0-9),
hyphens ("-"), underscores ("_"), colons (":"), and periods ("."). These
values are case-sensitive.

However, that's irrelevant, since the type of the name attribute is
CDATA, not NAME or ID. The quoted element is valid HTML.

/L
 
P

Pasquale

Lasse said:
$tP4.6854@clgrps12:

<input type="radio" name="Product_Attributes[2]:value" value="Black">
Poor choice of name for this element. In particular, I question your use
of [] and :


It does look odd, but it might be needed for some server side
processor.

Here's what HTML4.0 says:

Attribute values of type ID and NAME must begin with a letter in the
range A-Z or a-z and may be followed by letters (A-Za-z), digits (0-9),
hyphens ("-"), underscores ("_"), colons (":"), and periods ("."). These
values are case-sensitive.


However, that's irrelevant, since the type of the name attribute is
CDATA, not NAME or ID. The quoted element is valid HTML.

That's good to know, thanks. So at this point it not working cannot be
explained or written somehow to work??

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top