1

We're trying to make one drop box change another. We have this code which works fine on Firefox, safari and chrome. But in IE 8+ changing the first dropdown makes no difference to the second. What do we have to change to make it work in IE ? Thanks,

We have this jquery:

    //set up the global variable maxChecks which stops donor ticking too many boxes
    var maxChecks
    var checkCount=0
    var boxeschecked = 0
    //now change the drop down
    jQuery.noConflict();
    jQuery(document).ready(function($) {
        $(function() {      
            $("#json-one").change(function() {
                if ($(this).val() >= "1" ) {
                    $("#hide1").slideDown("fast"); //Slide Down Effect
                }
                var $dropdown = $(this);
                var key = $dropdown.val();
                var vals = [];
                switch(key) {
            case '1': document.getElementById("t3").innerHTML ="<option value=2>&pound;2.50 per month</option>, <option value=3>&pound;30 per year</option>, <option value=1>A single donation of &pound;30</option>"; maxChecks=1; boxeschecked=0; checkCount=0; document.getElementById("nsdiv").innerHTML =""; for (var i = 0; i < 1 ; i++) {document.getElementById("nsdiv").innerHTML +='<input type="hidden" name="childid[]" value="newchild" checked>';} break;
            case '2': document.getElementById("t3").innerHTML ="<option  value=5>&pound;5 per month</option>, <option value=4>&pound;60 per year</option>, <option value=22>A single donation of &pound;60</option>"; maxChecks=2; boxeschecked=0; checkCount=0; document.getElementById("nsdiv").innerHTML =""; for (var i = 0; i < 2 ; i++) {document.getElementById("nsdiv").innerHTML +='<input type="hidden" name="childid[]" value="newchild" checked>';} break;

case 'base': vals = ['-'];
                }
                $jsontwo.empty();
            });
        });
    });

and this is the html:

    <select id="json-one" name="json-one">
        <option selected value="base">Please select</option>
        <option value="1">1 child</option>
        <option value="2">2 children</option>
    </select>
    <!-- this select box will be hidden at first -->
    <div style="display:none;" id="hide1">
        By donating <select id="t3" name="t3"><option>-</option></select>
    </div>
Roko C. Buljan
  • 180,066
  • 36
  • 283
  • 292
oliver
  • 13
  • 1
  • 3

1 Answers1

1

The below appears to be working in IE:

    //set up the global variable maxChecks which stops donor ticking too many boxes
    var maxChecks;
    var checkCount=0;
    var boxeschecked = 0;
    //now change the drop down
    jQuery.noConflict();
    jQuery(document).ready(function($) {
        $(function() {      
            $("#json-one").change(function() {
                if ($(this).val() >= "1" ) {
                    $("#hide1").slideDown("fast"); //Slide Down Effect
                }
                var key = $(this).val();
                var vals = [];
            switch(key) {
              case "1": 
                $("#t3").html('<option value=2>&pound;2.50 per month</option> <option value=3>&pound;30 per year</option> <option value=1>A single donation of &pound;30</option>');
                maxChecks=1; 
                boxeschecked=0; 
                checkCount=0; 
                $("#nsdiv").html('');
                for (var i = 0; i < 1 ; i++) {
                    $("#nsdiv").append('<input type="hidden" name="childid[]" value="newchild" checked>');
                } 
                break;
              case "2": 
                $("#t3").html('<option  value=5>&pound;5 per month</option> <option value=4>&pound;60 per year</option> <option value=22>A single donation of &pound;60</option>'); 
                maxChecks=2; 
                boxeschecked=0; 
                checkCount=0; 
                $("#nsdiv").html('');
                for (var i = 0; i < 2 ; i++) {
                    $("#nsdiv").append('<input type="hidden" name="childid[]" value="newchild" checked>');
                } 
                break;

              case 'base': 
                vals = ['-'];
                break;
            }
            });
        });
    });
​

See here for an example: http://jsfiddle.net/m6A8z/

johnmadrak
  • 867
  • 5
  • 7
  • 2
    @oliver - So why don't you ask for an explanation before accepting the answer? – j08691 Jul 16 '12 at 21:15
  • I've swapped out your use of innerHTML for jQuery's append/html methods. IE can sometimes act strangely when using innerHTML against form elements. jQuery's methods are usually programmed to counteract issues that may occur due to the differences between the various browsers. – johnmadrak Jul 16 '12 at 21:19
  • excellent! I did spend some time googling and looking at stackoverflow for innerHTML but could never pin down what the alternative was. (I am volunteering to build this thing - not an expert!) Thanks a lot. – oliver Jul 16 '12 at 21:25