enter image description here In my calculation, calculations of V22 and h3 , but neither of them counts. Please help what's the matter.

 function proverka(input) { var value = input.value; var rep = /[-;":'a-zA-Zа-яА-Я\\=`ё/*++!@#$%\^&_№?><]/; if (rep.test(value)) { value = value.replace(rep, ''); input.value = value; } } function areaRectangle13(){ this.calc3(); var d10=document.forma1.t43.value||0; var d20=document.forma1.t44.value||0; var d30=document.forma1.t45.value||0; var D1=document.forma1.t46.value||0; var h1=document.forma1.t47.value||0; var h2=document.forma1.t48.value||0; var h3 = 4546-(h1+h2); document.forma1.t49[0].value = h1; document.forma1.t49[1].value = h2; document.forma1.t49[2].value = h3; } if ( (d10 == 0) || (d20 == 0) || (d30 == 0) || (h1 == 0) || (h2 == 0) || (h3 == 0) ) { alert('Входные данные не могут быть равны 0'); return; } if ( (d10 < 0) || (d20 < 0) || (d30 < 0) || (h1 < 0) || (h2 < 0) || (h3 < 0) ) { alert('Входные данные не могут быть меньше 0'); return; } var V22=0.785*1.04*( (D1*D1-d10*d10)*h1 + (D1*D1-d20*d20)*h2 + (D1*D1-d30*d30)*h3 ); document.forma1.res13.value=V22.toFixed(2); } function calc3() { //в подрасчёте есть промежуточное значение h3 console.log(1); //пользователь узнает чему равно h3, только после ввода p1,p2 и m var h1=document.forma1.t47.value||0; var h2=document.forma1.t48.value||0; var h3 = 4546-(h1+h2); document.forma1.t49[0].value = h1; document.forma1.t49[1].value = h2; document.forma1.t49[2].value = h3; } document.addEventListener("DOMContentLoaded", function (event) { document.forma1.t47.addEventListener("keyup", calc3); document.forma1.t48.addEventListener("keyup", calc3); }); 
 <form name="forma1" style="background-color:#44944A;"> <!-- поменяю цвет формы --> <div id="resizable"> <br> <!--"подрасчёт 4.3"--> <table align="center"> <p align="center">Количество жидкости, необходимое для промывки излишков цементного раствора</p> <tr> <td height="40px"> <tr> <td height="40px"> <div class="price">Наружний диаметр НКТ, соответственно, 60мм, м;</div> <input name="t43" id="t43" type="text" align="right" size="4" maxlength="8" onkeyup="return proverka(this)"> </td> </tr> <tr> <td height="40px"> <div class="price">Наружний диаметр НКТ, соответственно,73мм, м;</div> <input name="t44" id="t44" type="text" align="right" size="4" maxlength="8" onkeyup="return proverka(this)"> </td> </tr> <tr> <td height="40px"> <div class="price">Наружний диаметр НКТ, соответственно,89мм, м;</div> <input name="t45" id="t45" type="text" align="right" size="4" maxlength="8" onkeyup="return proverka(this)"> </td> </tr> <tr> <td height="40px"> <div class="price">Внутренний диаметр эксплуатационной колонны, м;</div> <input name="t46" id="t46" type="text" align="right" size="4" maxlength="8" onkeyup="return proverka(this)"> </td> </tr> <tr> <td height="40px"> <div class="price">Длина колонны нижней секции заливочных труб, м;</div> <input name="t47" id="t47" type="text" align="right" size="4" maxlength="8" onkeyup="return proverka(this)"> </td> </tr> <tr> <td height="40px"> <div class="price">Длина колонны средней секции заливочных труб, м;</div> <input name="t48" id="t48" type="text" align="right" size="4" maxlength="8" onkeyup="return proverka(this)"> </td> </tr> <tr> <td height="40px"> <div class="price">Длина колонны верхней секции заливочных труб, м;</div> <input name="t49" id="t49" type="text" align="right" size="4" maxlength="8" onkeyup="return proverka(this)"> </td> </tr> <tr> <td> <input type="button" name="button" value="Вычислить" onClick="areaRectangle13();"> <input type="text" name="res13" size="10"> </td> </tr> </table> </div> <br> </form> 

When you click on the "Calculate" V22 , V22 should be considered, and when you click on t49 , h3 should be considered V22

Fixed your script, but h3 still does not count when clicking on t49

 function areaRectangle13(){ this.calc3(); var d10=document.forma1.t43.value||0; var d20=document.forma1.t44.value||0; var d30=document.forma1.t45.value||0; var D1=document.forma1.t46.value||0; var h1=document.forma1.t47.value||0; var h2=document.forma1.t48.value||0; var h3 = 4546-(h1+h2); if ( (d10 == 0) || (d20 == 0) || (d30 == 0) || (h1 == 0) || (h2 == 0) || (h3 == 0) ) { alert('Входные данные не могут быть равны 0'); return; } if ( (d10 < 0) || (d20 < 0) || (d30 < 0) || (h1 < 0) || (h2 < 0) || (h3 < 0) ) { alert('Входные данные не могут быть меньше 0'); return; } var V22=0.785*1.04*( (D1*D1-d10*d10)*h1 + (D1*D1-d20*d20)*h2 + (D1*D1-d30*d30)*h3 ); document.forma1.res13.value=V22.toFixed(2); } function calc3() { //в подрасчёте есть промежуточное значение p console.log(1); //пользователь узнает чему равно p, только после ввода p1,p2 и m var h1=document.forma1.t47.value||0; var h2=document.forma1.t48.value||0; var h3 = 4546-(h1+h2); document.forma1.t49[0].value = h1; document.forma1.t49[1].value = h2; document.forma1.t49[2].value = h3; } document.addEventListener("DOMContentLoaded", function (event) { document.forma1.t47.addEventListener("keyup", calc3); document.forma1.t48.addEventListener("keyup", calc3); }); 
  • And where is the code from the function proverka ? - VenZell
  • this is another, input test, without letters and negative numbers <script> <! - we prohibit the user to enter letters -> function proverka (input) {var value = input.value; var rep = / [-; ": 'a-zA-Zа-ЯА-Я \\ =` ё / * ++! @ # $% \ ^ & _ №?> <] /; if (rep.test (value )) {value = value.replace (rep, ''); input.value = value;}} </ script> - Rem
  • @Rem you wrote должно считаться , but how really? What's happening? NaN ? Ps. jQuery does not consider, considers javascript - Vasily Barbashev
  • when you click on the "Calculate" button, nothing happens at all, even if you enter a zero in any form window, it does not display a dialog box about it, and the console is generally useless, it gives me an error that the function areaRectangle13 () is undefined, although defined in the form onClick = "areaRectangle13 ();"> - Ram
  • Well, at least in your code, the number of opening braces does not match the number of closing braces. - Alex Krass

1 answer 1

Error 1.

Learn to adhere to formatting, in this case most of the errors of incorrect markup or code will be detected immediately. In this case, in HTML you have two extra tags: <tr> and <td height="40px"> at the beginning of the table and there were extra brackets in JavaScript.

Error 2.

If you use a function inside HTML, then you need to make sure that it exists at this point in time.

Imitation of your console error:

 <input type="button" name="button" value="Вычислить" onClick="areaRectangle13();"> <script>function areaRectangle13 (){ }</script> 

Correction:

 <script>function areaRectangle13 (){ }</script> <input type="button" name="button" value="Вычислить" onClick="areaRectangle13();"> 

And best of all, use addEventListener after loading the document, so as not to depend on the connection order of the script.

Error 3.

You have a very strange reference to the element as an array in the code: document.forma1.t49[0] . I do not know what you wanted to achieve with this, but it will not work like that, because element is not an array.


Only then can we proceed to testing the calculations themselves. I hope you can do it yourself somehow, well, or at least try for a start.