www.webdeveloper.com
Results 1 to 2 of 2

Thread: Javascript if statement in form

Hybrid View

  1. #1
    Join Date
    Apr 2012
    Posts
    4

    Javascript if statement in form

    I have several if statements that manipulate a form on an ecommerce site. There are two links that specify the situations I am in.

    Link: http://www.hickorylax.com/detail.cfm?pid=1
    Note: The addbranding2_yn checkbox is not defined on this product
    Situation: Click both boxes (shield pro and branding) and try to submit the form, it correctly throws an error saying you can't do that. However, try to enter illegal characters (!, / etc) and it won't throw an alert as it is supposed to. It is not processing the for loop to validate special characters. If statements in the function validatechars() are not processed.

    Link: http://www.hickorylax.com/detail.cfm?pid=28
    Note: The addshield_yn checkbox is not shown or defined on this product
    Situation: Click the first branding box and type in illegal characters and it won't throw an error. Click the checkboxes and leave textboxes blank and it wont throw an error (it is supposed to). If statements in the function validatechars() are not processed.

    Your help is appreciated.

  2. #2
    Join Date
    Apr 2012
    Posts
    4

    The if statement not being processed - Help please

    The issue seems to be when the addshield_yn checkbox doesnot appear (is not defined) in the form... it doesn't process any of the other if statements below it.

    Code:
    <script language="javascript" type="text/javascript">
    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;
        }
      }
    }
    
    }
    </script>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles