title: On load on a select option
body: <p>I have a select option that when it changes it activates a script. What I'm trying to do is at the start when there is a selected value in the select option It would also activate the script. Right now here is my code</p>
  
  <p>I know that onload does not work on select option. So could you give me an idea for an alternative?
  Here is my code</p>
  
  <pre><code>&lt;script&gt;
  
  function getState(val) {
  
      var group = $("#group").val();
          $.ajax({
              type: "GET",
              url: "&lt;?=base_url()?&gt;personnel/get_division/"+val,
              data:{"group": group},
              success: function(data){
                  $('#div1').html(data);
               }
          }); 
  }
  &lt;/script&gt;
  
  &lt;select id="grp" name="group" class="cust_fields" onChange="getState(this.value);"&gt;
  
                      &lt;option value=""&gt; -- Select -- &lt;/option&gt; 
  
                      &lt;?php $table = "tbl_group"; $select = "g_name, g_id"; ?&gt;
  
                      &lt;?php foreach($ddl1 as $row1){ ?&gt; 
  
                      &lt;option value="&lt;?=$row1['g_id']?&gt;"&gt; &lt;?=$row1['g_name']?&gt; &lt;/option&gt; 
  
                      &lt;?php } ?&gt;
  
                  &lt;/select&gt;
  </code></pre>