-
AuthorPosts
-
August 18, 2017 at 11:23 am #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
August 18, 2017 at 5:33 pm #840958Hey 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 ShannonAugust 21, 2017 at 10:06 am #841926Hi Jordan,
the scripts work on it’s own. As soon as i add more than one script, only one ist working…
Tobi
August 21, 2017 at 3:24 pm #842045Hi 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,
VictoriaAugust 21, 2017 at 4:39 pm #842079Hi 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
August 21, 2017 at 4:46 pm #842084Hi,
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 ShannonAugust 22, 2017 at 2:59 pm #842587Hi Jordan,
Console gives me:
Uncaught TypeError: Cannot read property ‘value’ of null
at add ((index):553)
at HTMLInputElement.onclick ((index):459)Regards, Tobi
August 22, 2017 at 4:22 pm #842639Hi,
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 ShannonAugust 23, 2017 at 4:49 pm #843172Hi 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
August 28, 2017 at 4:21 am #844623Hi,
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 -
AuthorPosts
- You must be logged in to reply to this topic.