Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are using jQuery you can also do this</p> <pre><code>$('#leaveCode').val('14'); </code></pre> <p>This will select the option with the value of 14</p> <p><strong>Edit:</strong></p> <p>With plain Javascript, this can also be achieved with two <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document#Methods" rel="nofollow noreferrer">Document methods</a></p> <p>with <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector" rel="nofollow noreferrer">querySelector</a>, you can select an element based on CSS selector </p> <pre><code>document.querySelector('#leaveCode').value = '14' </code></pre> <p>Or the more established approach, with <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById" rel="nofollow noreferrer">getDocumentById</a>, that will, as the name of the function implies, let you select an element based on there <code>id</code></p> <pre><code>document.getElementById('leaveCode').value = '14' </code></pre> <p>You can run the bellow code snipped to see these methods and the jQuery function in action.</p> <p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false"> <div class="snippet-code snippet-currently-hidden"> <pre class="snippet-code-js lang-js prettyprint-override"><code>const jQueryFunction = () =&gt; { $('#leaveCode').val('14'); } const querySelectorFunction = () =&gt; { document.querySelector('#leaveCode').value = '14' } const getElementByIdFunction = () =&gt; { document.getElementById('leaveCode').value='14' }</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>input { display:block; margin: 10px; padding: 10px }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;select id="leaveCode" name="leaveCode"&gt; &lt;option value="10"&gt;Annual Leave&lt;/option&gt; &lt;option value="11"&gt;Medical Leave&lt;/option&gt; &lt;option value="14"&gt;Long Service&lt;/option&gt; &lt;option value="17"&gt;Leave Without Pay&lt;/option&gt; &lt;/select&gt; &lt;input type="button" value="$('#leaveCode').val('14');" onclick="jQueryFunction()" /&gt; &lt;input type="button" value="document.querySelector('#leaveCode').value = '14'" onclick="querySelectorFunction()" /&gt; &lt;input type="button" value="document.getElementById('leaveCode').value = '14'" onclick="getElementByIdFunction()" /&gt; &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;</code></pre> </div> </div> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload