calin-beard
11/13/2017 - 5:16 PM

Change value of the Dropdown options

<!--START code - change dropdown options value-->
<script>
    $(document).ready(function() {
        //define the target field label
        var fieldLabel = 'Choose your qualification';
        //store the options in an object w/ the old value as the property name and the new value as the property value
        var options = {
            "Certificate III in Business": "E1056IN",
            "Certificate IV in Business": "E1129IN",
            "Diploma of Business": "E1058IN",
            "Certificate III in Business Administration": "E1061IN",
            "Certificate IV in Business Administration": "E1063IN",
            "Certificate IV in Human Resources": "E1068IN",
            "Diploma of Human Resources Management": "E1069IN",
            "Certificate IV in Leadership and Management": "E1057IN",
            "Diploma of Leadership and Management": "E1070IN",
            "Certificate IV in Project Management Practice": "E1075IN",
            "Diploma of Project Management": "E1076IN",
            "Certificate IV in Marketing and Communication": "E1131IN",
            "Diploma of Social Media Marketing": "E1198IN",
            "Certificate in Digital Photography": "E0161IN",
            "Diploma of Interior Design and Decoration": "E1035IN",
            "Certificate II in Information, Digital Media and Technology": "E1119IN",
            "Certificate III in Information, Digital Media and Technology": "E1121IN",
            "Certificate IV in Web-Based Technologies": "E1110IN"
        };
        
        //set a 1 second timeout after the page loads
        setTimeout(function() {
            //go through each option from the dropdown
            $('select[name="' + btoa(fieldLabel) + '"] option').each(function(i, e) {
                $(e).val(function(i, v) {
                    if(options[v]) {
                        //if the current value is defined as the options object's property then return the value of the property 
                        return options[v];
                    } else {
                        //if not return the value as it was
                        return v;
                    }
                })
            });
        }, 1000);
    }); // ready

</script>
<!--END code - change dropdown options value-->
<script>
  $(document).ready(function() {

    var fieldLabel = 'Program of Interest:';

    var switchValue = function(index, code) {
      $('select[name="' + window.btoa(fieldLabel) + '"] option:nth-child(' + index + ')').val(code);
    }

    for (var i = 2; i < 12; i++) {
      switch (i) {
        case 2:
          switchValue(i, 'a035B0000005OwuQAE');
          break;
        case 3:
          switchValue(i, 'a035B0000005P1eQAE');
          break;
        case 4:
          switchValue(i, 'a035B0000005P03QAE');
          break;
        case 5:
          switchValue(i, 'a035B0000005P29QAE');
          break;
        case 6:
          switchValue(i, 'a035B0000005P1hQAE');
          break;
        case 7:
          switchValue(i, 'a035B0000005P1cQAE');
          break;
        case 8:
          switchValue(i, 'a035B0000005P0QQAU');
          break;
        case 9:
          switchValue(i, 'a035B0000005P0SQAU');
          break;
        case 10:
          switchValue(i, 'a035B0000005P0UQAU');
          break;
        case 11:
          switchValue(i, 'a035B0000005P0WQAU');
          break;
      }
    }
  });

</script>
<script> 
ijQuery(document).ready(function($){ 
  setTimeout( function() {
		ijQuery( 'option[value="Current option name]').attr("value", "The new value for option");
  }, 1000 );
}); // ready
</script>