title: How to Check regex attribute of an input after page load
body: <p>There is a selectbox. and a textbox with specific pattern for Hostname.in this case when my selectbox changes the pattern of the textbox will change. my question is how can i check the selectbox value onload of the body? and check the pattern? for example if the selectbox was "Nx" at first. i would like to check the pattern . and when selectbox changes the value change.</p>
  
  <p>here is my code that works only onchange of selectbox:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(function(){
    $('select[name=type]').change(function(){
      var $option = $(this).find(":selected");
      $('input[name=hostInput]').attr('pattern', $option.attr('data-pattern'));
      $('input[name=hostInput]').attr('placeholder', $option.attr('data-placeholder'));
      $('input[name=hostInput]').attr('title', $option.attr('data-title'));
    });
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.to_validate:invalid {
    color: navy;
    outline: none; 
    border-color: #ff1050;
    box-shadow: 0 0 10px #ff0000;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;form&gt;
    &lt;select name="type" class="minimal"&gt;
      &lt;option value="Record" hidden&gt;Record&lt;/option&gt;
      &lt;option value="NS" selected data-pattern="(?!\d+(?:\.\d+){3}$)(([a-zA-Z\d]|[a-zA-Z\d][a-zA-Z\d-]*[a-zA-Z\d])\.)*([A-Za-z\d]|[A-Za-z\d][A-Za-z\d-]*[A-Za-z\d])" data-placeholder="Hostname" data-title="Wrong host"&gt;NS&lt;/option&gt;
      &lt;option value="MX" data-pattern="(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])" data-placeholder="IP address" data-title="Wrong Ip Placeholder"&gt;MX &lt;/option&gt;
    &lt;/select&gt;
    
    &lt;br/&gt;
   
    &lt;input type="text" name="hostInput" placeholder="Hostname" class="to_validate" title="Wrong host"/&gt;
    
    
    &lt;button type="submit"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>