මේ Code එකේ අවුල මොකක්ද HTML, JS, CSS

geeko

Well-known member
  • Mar 18, 2013
    7,470
    4,471
    113
    Applicable select කලාම Hide කරලා තියෙන Fied එක Display වෙන්න ඕනේ

     
    • Like
    Reactions: thedigit2s

    kanchana071

    Active member
  • Apr 20, 2011
    847
    129
    43
    Gampaha, Sri lanka
    const selectElementOrc1 = document.getElementById('meta_orcapplicable');
    const displayElementOrc1 = document.getElementById('new_orcincluded');

    selectElementOrc1.onchange = function() {
    if (selectElementOrc1.value === 'Applicable') {
    displayElementOrc1.style.display = 'block';
    } else {
    displayElementOrc1.style.display = 'none';
    }
    };
     

    geeko

    Well-known member
  • Mar 18, 2013
    7,470
    4,471
    113
    const selectElementOrc1 = document.getElementById('meta_orcapplicable');
    const displayElementOrc1 = document.getElementById('new_orcincluded');

    selectElementOrc1.onchange = function() {
    if (selectElementOrc1.value === 'Applicable') {
    displayElementOrc1.style.display = 'block';
    } else {
    displayElementOrc1.style.display = 'none';
    }
    };
    real code ekedi ehema wada karanne na.
    Css eke important dannama venawa real code ekedi. Console ekedi me error eka enne

    Uncaught TypeError: Cannot set properties of null (setting 'onchange')
     
    Last edited:

    jzx

    Well-known member
  • Apr 26, 2023
    861
    1,679
    93
    Mars
    Try kala eth hariyanne na. are error eka thamai pennanne. script eka footer ekatama dalath baluwa eth hariyanne na

    මට ඕක ගැන ගැන idea එකක්නම් නෑ බං. මේ මට හම්බුන ඒවා. stackoverflow එකේ එකක් තිබ්බා, ඒකෙ තිබ්බෙ chrome එකෙන් එක එන error එකක්. මේ වෙන එකක තිබ්බ එකක් How to Fix "cannot set properties of null" Errors in JS. පල්ලෙහ තියෙන්නෙ chat gpt එකෙන් ආපු එක
    The error "Uncaught TypeError: Cannot set properties of null (setting 'onchange')" indicates that the element with the ID `'meta_orcapplicable'` is not found in the HTML document. As a result, the `getElementById` method returns `null`, and you cannot set the `onchange` property on a null value.

    To avoid this error, ensure that the HTML element with the ID `'meta_orcapplicable'` exists in your HTML document and is loaded before the JavaScript code executes. Double-check that the ID is spelled correctly and that there are no typos.

    Here are a few things you can check:

    1. Verify that the HTML element has the correct ID:

    Code:
    ```html
       <select id="meta_orcapplicable">
         <!-- options here -->
       </select>
       ```

    2. Ensure that your JavaScript code is placed after the HTML element or use an event listener like `DOMContentLoaded` to ensure the HTML is loaded before executing the JavaScript code:

    Code:
    ```javascript
       document.addEventListener('DOMContentLoaded', function() {
         // Your code here
       });
       ```

    3. Make sure that your JavaScript code is placed at the end of the HTML body, just before the closing `</body>` tag:

    Code:
    ```html
       <script>
         // Your code here
       </script>
       ```

    By following these steps, you should be able to avoid the "Cannot set properties of null" error. If the issue persists, please share your HTML code so that I can assist you further.
     

    geeko

    Well-known member
  • Mar 18, 2013
    7,470
    4,471
    113
    මට ඕක ගැන ගැන idea එකක්නම් නෑ බං. මේ මට හම්බුන ඒවා. stackoverflow එකේ එකක් තිබ්බා, ඒකෙ තිබ්බෙ chrome එකෙන් එක එන error එකක්. මේ වෙන එකක තිබ්බ එකක් How to Fix "cannot set properties of null" Errors in JS. පල්ලෙහ තියෙන්නෙ chat gpt එකෙන් ආපු එක
    Me okkoma kala hariyanne na ban

    oka gpt or bard dala ahanna meke waradda mokkd kiyala
    okkoma kala, hariyanne na
    ------ Post added on Jun 24, 2023 at 2:19 AM
     

    Nidarshana_k

    Well-known member
  • Feb 19, 2022
    29,554
    1
    51,237
    113
    ප*යාගල
    sorry.com
    Machan Any Idea? Css eke important dannama venawa real code ekedi. Console ekedi me error eka enne

    Uncaught TypeError: Cannot set properties of null (setting 'onchange')
    Default value rkak deelafa balanna dropdown ekata.

    Nathnm display wenuwata visibility propery use krnna balanna.
    ------ Post added on Jun 24, 2023 at 2:23 AM
     

    rockmon

    Well-known member
  • Jul 31, 2017
    3,500
    3,889
    113
    real code ekedi ehema wada karanne na.
    Css eke important dannama venawa real code ekedi. Console ekedi me error eka enne

    Uncaught TypeError: Cannot set properties of null (setting 'onchange')
    null ekaka onchage set kranna ba kiyala ne kiyanne

    meke null eka wenne selectElementOrc1 variable eka neda

    eka null wenne element eka hariyta selct wenne nathi nisa.

    element eka hariyta select wenne naththe ekko wrong id, or element eka thama dom eke na
     
    • Like
    Reactions: Asmodeus

    gulp

    Active member
  • Mar 17, 2015
    130
    133
    43
    Put below after your </form> tag:

    <style>
    #new_orcincluded {display:none;}
    </style>
    <script>
    const selectElementOrc1 = document.getElementById('meta_orcapplicable');
    const displayElementOrc1 = document.getElementById('new_orcincluded');
    selectElementOrc1.onchange = function() {
    if (selectElementOrc1.value === 'Applicable') {
    displayElementOrc1.style.display = 'block';
    } else {
    displayElementOrc1.style.display = 'none';
    }
    };
    </script>