www.webdeveloper.com
Results 1 to 8 of 8

Thread: Conditional Radio Arrays + Chained Selects Work in Mozilla, Not IE

  1. #1
    Join Date
    Jun 2008
    Location
    Schaumburg, IL
    Posts
    16

    Unhappy Conditional Radio Arrays + Chained Selects Work in Mozilla, Not IE

    Hello,

    I have been working on this same page off and on for months. I've been trying to learn as I go and I know that the error console on this code is packed full of wonderful things I still have to fix, but for now I'm really pretty stuck on why IE shows an Error on line 232, character 5 of my code.

    I have this form set up so that there are conditional text areas, radio arrays and then also chained selects. In Mozilla this form works fine but in IE the chained selects will not populate.

    No support I have read gives me assistance on this and I am guessing it is something small that I just overlooked?

    The form submits using FormToEmail.php and is HERE . I tried posting the full code here but it was far too long to fit into the allowed length.

    I realize the code is a mess and am currently working on a much cleaner version but for now I must get the form fixed.

    If anyone could offer some advice I'd really appreciate it. I hate to ask for just a simple answer but I'm guessing/hoping that's what it is.


    Thanks to anyone who could give me a hand here.

    Kristin

  2. #2
    Join Date
    Jun 2008
    Location
    Schaumburg, IL
    Posts
    16

    please refer to this previous thread


  3. #3
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Appears to be working, issue solved?
    At least 98% of internet users' DNA is identical to that of chimpanzees

  4. #4
    Join Date
    Jun 2008
    Location
    Schaumburg, IL
    Posts
    16

    Issue partly solved

    I was able to locate an updated configuration file on the original script which fixed whatever the bug is.

    Now my problem is conditional validation. Is this even possible?

    I have a radio at the top that when you click yes or no it makes certain text areas visible or invisible. I want to be able to make certain fields required depending on wehther the first array is checked with yes or with no but cannot seem to figure it out.

  5. #5
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Check the radios:
    Code:
    if(document.myform.CustomerRadio1[0].checked) {
    // new customer
    // validate Name, etc.}
    else if(document.myform.CustomerRadio1[1].checked) {
    // existing customer
    // validate  Customer No. and Company Name
    }
    else {
    // error: select customer type}
    At least 98% of internet users' DNA is identical to that of chimpanzees

  6. #6
    Join Date
    Jun 2008
    Location
    Schaumburg, IL
    Posts
    16

    Unhappy

    I tried using this

    if(document.myform.CustomerRadio1[0].checked) {
    // new customer
    // validate Name, etc.}
    else if(document.myform.CustomerRadio1[1].checked) {
    // existing customer
    // validate Customer No. and Company Name
    }
    else {
    // error: select customer type}
    Which did not work for me although my modifications may have been incorrect. I also attempted using this fix:

    Code:
    function MM_validateForm() { //v4.0
      if (document.getElementById){
        var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
        for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
          if (val) { nm=val.name; if ((val=val.value)!="") {
            if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
              if (p<1 || p==(val.length-1)) errors+='- '+nm+' Must Contain an Email Address.\n';
            } else if (test!='R') { num = parseFloat(val);
              if (isNaN(val)) errors+='- '+nm+' Must Contain a Valid Phone Number.\n';
              if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
                min=test.substring(8,p); max=test.substring(p+1);
                if (num<min || max<num) errors+='- '+nm+' Must Contain a Number Between '+min+' and '+max+'.\n';
          } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' Is Required.\n'; }
        } if (errors){ alert('Please Complete All Required Fields:\n'+errors); }
    	if(document.myform.CustomerRadio1[0].checked != "") && (document.myform.CustomerRadio1[1].checked == "") {
    alert("Please enter Company Name");
    
    return false;
    		} 
    		else
    		return true;
    	}  
        document.MM_returnValue = (errors =='');
    } }
    //-->
    </script>
    Which completely broke everything. The validation didn't work at all after that so I returned back to the original version.

    The goal:
    If the CustomerRadio[0] is checked (Meaning they clicked no) I would like to have the following fields required:
    first-name
    last-name
    company
    workphone
    address1
    city
    state
    country

    If the CustomerRadio[1] is checked (Meaning they clicked yes) I would like to have the following fields required:
    customername
    first-name
    last-name
    workphone

    So that current customers, if choosing to click yes and give us their company name, are not required to enter contact info we already have.

    I know this is a mess.

    The form was a problem for me since the beginning since I chose to use the FormtoEmail.php submission coding and the MMValidation which left me pretty limited at my experience level. I've learned how to adjust javascript in many other ways but the forms still just have me... blown.

  7. #7
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Because of the type of validation function you're using, you need to put the condition in the onclick handler. Something like:
    Code:
    onClick="if( this.form.CustomerRadio1[0].checked )
    MM_validateForm('first-name','','R','last-name','','R','workphone','','RisNum','address1','','R','city','','R','state','','R','country','','R');
    else
     MM_validateForm( DIFFERENT PARAMETERS HERE );
    
    return document.MM_returnValue;"
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  8. #8
    Join Date
    Jun 2008
    Location
    Schaumburg, IL
    Posts
    16

    Thank you!

    So your code help very much

    This was the final code I entered:

    Code:
    <input type="submit" class="buttons" onClick="if( this.form.CustomerRadio1[0].checked )
    MM_validateForm('first-name','','R','last-name','','R','workphone','','RisNum','address1','','R','city','','R','state','','R','country','','R','company','','R');
    else
     MM_validateForm('first-name','','R','last-name','','R','workphone','','RisNum','customername','','R');
    
    return document.MM_returnValue;" value="Send"/>
    And it works great.

    Thank you so much.

    For some reason now, on load.. one of the customer radio arrays is already selected. I'm not sure why. on the other page, located here you can see the radios are not selected on load. The ones on this page weren't either. I see nothing that should have caused that effect.
    Last edited by kristingish; 10-05-2008 at 04:49 PM.

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