By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,568 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,568 IT Pros & Developers. It's quick & easy.

radio element.type undefined

P: n/a
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>

Aug 25 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Pasquale <sp*****@NOTHNXtelusplanet.netwrote in news:5PIHg.18970
$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 :

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.

Aug 25 '06 #2

P: n/a
Jim Land <RrrrFfffTttt(NO)@(SPAM)hotmail.comwrites:
Pasquale <sp*****@NOTHNXtelusplanet.netwrote in news:5PIHg.18970
$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.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Aug 25 '06 #3

P: n/a
Lasse Reichstein Nielsen <lr*@hotpop.comwrote in
news:ir**********@hotpop.com:
the type of the name attribute is
CDATA, not NAME or ID. The quoted element is valid HTML.
Oops! You're right. From the HTML 4.0 spec:

<INPUT Attribute Specifications
* NAME=CDATA
Aug 26 '06 #4

P: n/a


Lasse Reichstein Nielsen wrote:
Jim Land <RrrrFfffTttt(NO)@(SPAM)hotmail.comwrites:

>>Pasquale <sp*****@NOTHNXtelusplanet.netwrote in news:5PIHg.18970
$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

>
/L
Aug 28 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.