The if statements in the following javascript are not processing correctly. Namely, it stops processing the if statements if the field addshield_yn is not shown in the form.
I have a form as specified below, programmed in coldfusion:
Javascript on the page is here:Code:<cfform action="cart.cfm" method="post" name="form_add"> <cfif fee_shield neq ""> <p><cfinput type="checkbox" name="addshield_yn" id="addshield_yn" value="Yes" /> <b> Add Shield Pro </cfif> <cfif fee_branding neq ""> <p><cfinput type="checkbox" id="addbranding_yn" name="addbranding_yn" value="Yes" onClick="showhidefield()"/><b>Add Custom Branding</b> </p> <div id="brandingdiv1" style="display:none;">Type your Custom Brand or Team Name Here:<br /> <textarea rows="3" name="branding" id="branding" cols="26" wrap="virtual" onkeyup="document.form_add.word_count.value=document.form_add.branding.value.length;" onkeypress="return imposeMaxLength(event, this, #maxchars#);"></textarea> <br /> special characters limited to: comma, apostrophe, pound, dash, and period<p> Character Count: <input type="text" name="word_count" size="2" disabled="disabled"></div> <cfif fee_branding2 neq ""> <cfinput type="checkbox" id="addbranding2_yn" name="addbranding2_yn" value="Yes" onClick="showhidefield2()" /> <b>Add Individual names or messages for each shaft on this order - $#fee_branding2# per shaft</b> <div id="brandingdiv2" style="display:none;"><p>Type your List of names or messages here separated by commas (max 24 characters each):<br /> <textarea rows="3" name="branding2" id="branding2" cols="26"></textarea><br /> special characters limited to: comma, apostrophe, pound, dash, and period</p></div> </cfif> </cfif> <p><b>Quantity of this exact shaft</b>: <select name="addquantity"> <cfloop from="#minqty#" to="#qtyavail#" index="i"> <option value="#i#">#i#</option> </cfloop> </select></p> <cfinput type="submit" class="submit" name="addtocart" value="Add To Cart" onClick="return validatechars()"> <cfelse> Out of Stock </cfif> </cfform>
Code:<script language="javascript" type="text/javascript"> function showhidefield() { var eSelect = document.getElementById('addbranding_yn'); var optOtherReason = document.getElementById('brandingdiv1'); if(eSelect.checked) { optOtherReason.style.display = 'block'; } else { optOtherReason.style.display = 'none'; addbranding2_yn.checked = false; } } function showhidefield2() { var eSelect = document.getElementById('addbranding2_yn'); var optOtherReason = document.getElementById('brandingdiv2'); if(eSelect.checked) { optOtherReason.style.display = 'block'; addbranding_yn.checked = true; brandingdiv1.style.display = 'block'; } else { optOtherReason.style.display = 'none'; } } function imposeMaxLength(Event, Object, MaxLen) { document.form_add.addbranding_yn.checked = true; return (Object.value.length <= MaxLen)||(Event.keyCode == 8 ||Event.keyCode==46||(Event.keyCode>=35&&Event.keyCode<=40)) } </script> function validatechars() { if(document.form_add.addbranding_yn.checked == true && document.form_add.addshield_yn.checked == true) { alert("You cannot select both custom branding and shield pro on this shaft. \nPlease remove one and try again."); return false;} if(document.form_add.addbranding_yn.checked == true && document.form_add.branding.value.length < 1) { alert("You selected branding but did not type in your custom brand. \nPlease either unselect branding or type in your custom brand and try again."); return false; } if(document.form_add.addbranding2_yn.checked == true && document.form_add.branding2.value.length < 1) { alert("You selected individual branding but did not type in your custom brand. \nPlease either unselect individual branding or type in your custom brand and try again."); return false;} var iChars = "!@$%^&*()+=[]\\\;/{}|\":<>?"; if (document.form_add.branding.value.length > 0) { for (var i = 0; i < document.form_add.branding.value.length; i++) { if (iChars.indexOf(document.form_add.branding.value.charAt(i)) != -1) { alert("Your custom brand has invalid special characters. \nPlease remove them and try again."); return false; } } } if (document.form_add.branding2.value.length > 0) { for (var i = 0; i < document.form_add.branding2.value.length; i++) { if (iChars.indexOf(document.form_add.branding2.value.charAt(i)) != -1) { alert("Your team list has invalid special characters. \nPlease remove them and try again."); return false; } } } }


Reply With Quote

Bookmarks