Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
102 views
in Technique[技术] by (71.8m points)

html - The second response is not displayed in JavaScript?

I enter 2 x and z coordinates. And the response should display 2 responses.

1 answer — Sum to the number 600. 2 answer - Difference from the number 600.

I have only entered one response, and then to the second script, not the first.

https://www.w3schools.com/code/tryit.asp?filename=GMFS5UGR7FWC

<!DOCTYPE html>
<html>
<body>
<script>

  var x, y, c;
  var outputText;
  
  function validate() {
  
    // get the input
    x = document.forms["input_form"]["aterm1"].value;
      y = document.forms["input_form"]["aterm2"].value;
      // validate a, b and c
      if (x == 0) {} else {
    // calculate 
    var a1 = x;
      var a2 = y;
      var a3 = 600;
      var a4 = (a1 +++ a3);
      var a5 = (a2 +++ a3);
      outputText = "<h>" + a4 + ", " + a5 + "</h> ";
  }
  
  // output the result (or errors)
  document.getElementById("1").innerHTML = outputText;
  
  }
</script>
<script>

  var x, y, c;
  var outputText;
  
  function validate() {
  
    // get the input
    x = document.forms["input_form"]["aterm1"].value;
      y = document.forms["input_form"]["aterm2"].value;
      // validate a, b and c
      if (x == 0) {} else {
    // calculate 
    var a1 = x;
      var a2 = y;
      var a3 = 600;
      var a4 = (a1 --- a3);
      var a5 = (a2 --- a3);
      outputText = "<h>" + a4 + ", " + a5 + "</h> ";
  }
  
  // output the result (or errors)
  document.getElementById("2").innerHTML = outputText;
  
  }
</script>

<h type="x">X</h>
<h type="z">Z</h>
<form name="input_form" action="javascript:validate();">
  <input type="text1" name="aterm1" size="5" required>
    <input type="text2" name="aterm2" size="5" required>
      <input type="submit" value="Готово">
      </form>
      
      <p type="ygol1" id="1">Первый угол</p> 
      <p type="ygol2" id="2">Второй угол</p>
      
    </div>
  </body>
</html>
question from:https://stackoverflow.com/questions/65621673/the-second-response-is-not-displayed-in-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<!DOCTYPE html>
<html>
  <body>

    <h type="x">X</h>
    <h type="z">Z</h>
    <form name="input_form" action="javascript:validate();">
      <input type="text1" name="aterm1" size="5" required>
      <input type="text2" name="aterm2" size="5" required>
      <input type="submit" value="Готово">
    </form>

    <p type="ygol1" id="1">Первый угол</p>
    <p type="ygol2" id="2">Второй угол</p>

    <script>
      function validate() {
        // get the input
        var x = document.forms["input_form"]["aterm1"].value;
        var y = document.forms["input_form"]["aterm2"].value;

        // output the result (or errors)
        document.getElementById("1").innerHTML = "<h>" + (x + 600) + ", " + (y + 600) + "</h>";
        document.getElementById("2").innerHTML = "<h>" + (x - 600) + ", " + (y - 600) + "</h>";
      }
    </script>
  </body>
</html>

https://www.w3schools.com/code/tryit.asp?filename=GMFZ3DNB6ELT


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...