Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #840819

    Hi there,

    i added this to my child theme’s functions.php:

    /**
    * BMI Calculation
    */

    function add_custom_js(){
    ?>
    <script>
    function add()
    {
    var x = document.getElementById(“bmi_1”).value;
    var y = document.getElementById(“bmi_2”).value;
    var z = document.getElementById(“bmi_sum”).value=((x*1)/((y*1)*(y*1)))*10000;
    document.getElementById(“bmi_sum”).value=Math.round(z*10)/10;

    }

    </script>

    <script>
    function add()
    {
    var u = document.getElementById(“th_1”).value;
    var v = document.getElementById(“th_2”).value;
    var w = document.getElementById(“th_sum”).value=(u*1)/(v*1);
    document.getElementById(“th_sum”).value=Math.round(w*100)/100;
    }
    </script>

    <?php
    }
    add_action(‘wp_footer’, ‘add_custom_js’);

    For some reason, the first script does not work.
    Deleting the second script makes the first one work immediately.

    Any idea what’s wrong?

    Thanks a lot, Tobi

    #840958

    Hey Tobias,

    Does the second script work on its own? I would assume if not, that is where the issue lies. Find the error in your second script.

    Best regards,
    Jordan Shannon

    #841926

    Hi Jordan,

    the scripts work on it’s own. As soon as i add more than one script, only one ist working…

    Tobi

    #842045

    Hi Tobi,

    Enable debug into log and try again, then look into the log for the error.

    And it’s not right, because the JavaScript functions have the same name. You should name the other one like add1() or some other name, it gets redefined by the later.

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #842079

    Hi Victoria,

    I’d like to avoid Debug Mode as the site is alreqdy online.

    Renaming unfourtunately did not help. There is still only one script at a time working (and without renaming anything).

    Any other idea?

    Thanks , Tobi

    #842084

    Hi,

    I would have to believe there is a naming conflict if they work on there own and not together. Are there console errors?

    Best regards,
    Jordan Shannon

    #842587

    Hi Jordan,

    Console gives me:

    Uncaught TypeError: Cannot read property ‘value’ of null
    at add ((index):553)
    at HTMLInputElement.onclick ((index):459)

    Regards, Tobi

    #842639

    Hi,

    Does those page contain any custom scripts? Also, be sure to text with plugins deactivated in order to rule out further conflicts.

    Best regards,
    Jordan Shannon

    #843172

    Hi Jordan,

    i tried to deactivate all plugins, same problem.

    Please have a look at the link below.

    And here’s the current code in functions.php:

    /**
    * BMI Calculation
    */

    function add_custom_js(){
    ?>
    <script>
    function add()
    {
    var x = document.getElementById(“bmi_1”).value;
    var y = document.getElementById(“bmi_2”).value;
    var z = document.getElementById(“bmi_sum”).value=((x*1)/((y*1)*(y*1)))*10000;
    document.getElementById(“bmi_sum”).value=Math.round(z*10)/10;

    }

    </script>

    <script>
    function add1()
    {
    var u = document.getElementById(“th_1”).value;
    var v = document.getElementById(“th_2”).value;
    var w = document.getElementById(“th_sum”).value=(u*1)/(v*1);
    document.getElementById(“th_sum”).value=Math.round(w*100)/100;
    }
    </script>

    <script>
    function add2()
    {
    var x = document.getElementById(“ebf_1”).value;
    var y = document.getElementById(“ebf_2”).value;
    var z = document.getElementById(“ebf_sum”).value=(x*24*0.9)+(x*24*0.9)*(y*1);
    document.getElementById(“ebf_sum”).value=Math.round(z*1)/1;
    }
    </script>

    <script>
    function add3()
    {
    var x = document.getElementById(“ebm_1”).value;
    var y = document.getElementById(“ebm_2”).value;
    var z = document.getElementById(“ebm_sum”).value=(x*24)+(x*24)*(y*1);
    document.getElementById(“ebm_sum”).value=Math.round(z*1)/1;
    }
    </script>

    <?php
    }
    add_action(‘wp_footer’, ‘add_custom_js’);

    I really am quite desperated, as these are simple calculations that need to work.

    Hope you have another idea….

    Thanks a lot, Tobi

    #844623

    Hi,

    Please look for this code:

    
    <p style="color: #000000">Umfang Taille (cm): <input type="text" id="th_1" value="70"> Umfang Hüfte (cm): <input type="text" id="th_2" value="90">
    
    <input type="button" value="Berechnen" onclick="add()">
    Taille-Hüfte Verhältnis: <input type="text" id="th_sum">
    
    

    The function name or the onclick attribute value in the button element should be “add1()”.,

    Best regards,
    Ismael

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.