View Full Version : Amend javascript function for new site (Quick job)

11-15-2010, 01:53 PM
Hi Guys,
I just need a tiny bit of javascript re-written,
all it does is check the a size has been selected in a form..
The trouble is on the old site it was a drop down, and on my newly designed site it is a radio buttons so I think that is interfering.. I need a JavaScript expert. :)

The original function:-

function checkSizes()
for(i=0; i<document.main.elements.length; i++)
if ( document.main.elements[i].name.match(/^colour_(.*)$/) && document.main.elements[i].value ) {
if ( document.getElementById("size_" + RegExp.$1).value == '' ) {
alert ('Please choose a size for all your items');
return false;

The page in which I want the function to occur:-
Example Product Page (http://www.test.steptoes.co.uk/product-display_Dr-Martens-13276_dGFibGU9cHJvZHVjdCZmaWVsZD1Db2RlMSZ2YWx1ZT0xMzI3Ng.ghtml)

The form specifics:-

<form action="basket.ghtml" method="post" name="main" target="_self" onsubmit="return checkSizes()">

[_foreach [_own Size_]_]
<div class="buttons">
<input type="radio" name="size_[_own ID_]" value="[_value_]" class="styled" /> <div class="label"> <span class="nohover">[_value_]</span>
<span class="onhover"></span>

<input type="submit" name="action" value="Add to Basket" class="button" />


So can anyone either edit my code or create a new piece of JavaScript to perform this function?
Thanks for your time.
Best Regards,