There are 4 fields and a button as a result. There is a function that calculates the result of entering each of the fields. How to organize output to display the result:

function Go() { var x1 = parseInt(document.forml.acht_mes.value); var x2 = parseInt(document.forml.kol_mes.value); var x3 = parseInt(document.forml.acht_den.value); var x4 = parseInt(document.forml.kol_den.value); var result=((x1*x2)+(x3*x4))/(x2+x4); } 

The onClick event should output the result of the function in the fifth field, as output:

 <form name="form1"> <input type="text" name="user" placeholder="Введите первое число" required="required" class="input-txt" name="acht_mes" id="acht_mes" /> <input type="text" name="user" placeholder="Введите второе число" required="required" class="input-txt" name="kol_mes" id="kol_mes" /> <input type="text" name="user" placeholder="Введите третье число" required="required" class="input-txt" name="acht_den" id="acht_den"/> <input type="text" name="user" placeholder="Введите четвертое" required="required" class="input-txt" name="kol_den" id="kol_den" /> <button type="submit" class="btn btn--right" onClick="Go();">Посчитать </button> </form> 
  • 2
    "output result" - where? The first step is to change type="submit" to type="button" , the second is to remove unnecessary name attributes, the third is to pay attention to the fact that even though the characters "1" and "l" are similar, document.forml does not exist. - Igor

1 answer 1

There are several options

1. Add another field to the form

 <input type="text" name="output" /> 

and insert the result into it:

 document.forml.kol_den.value = result; 

2.Add HTML element

 <div>Результат: <span id="output"></span></div> 

and insert the answer in the span

 document.getElementById("output").innerHTML = result; 

3. Output the result to alert

 alert("Результат: " + result); 

It is possible to come up with something else, because These methods are basic, and expand to infinity.