简体   繁体   中英

How I get values updating/refreshing related input areas in Javascript?

I have a form and when I press the Try button it returns values for the 3rd and 6th input fields of the form according to the values entered in 1,2 and 5.6. Also, the 7th input field combines the 3rd and 6th results. My question is how can I get the result values from input fields 3 and 6 without clicking the Try It button and also update the input field 7 without refreshing the page?

 <script type="text/javascript">
   function concatenate(/*String*/string_one, /*String*/string_two, /*boolean*/with_space) {
    if (with_space===true) {
     return string_one+'/'+string_two;
    }
    else {
     return string_one+string_two;
    }
   }
   function join_names() {
    var input_name_first = document.getElementsByName('ht')[0].value;
    var input_name_last = document.getElementsByName('ft')[0].value;
    var input_name_full = document.getElementsByName('htft')[0];
    var var_name_full = concatenate(input_name_first, input_name_last, true);
    input_name_full.value = var_name_full;
   }
  </script>
  
  
  <script type="text/javascript">
function myFunctionFt() {
  var home = document.getElementById("home_score").value;
    var away = document.getElementById("away_score").value;
  var results;
  if (home > away) {
    results = "1";
  } else if (home < away) {
    results = "2";
  }  else if (home = away) {
    results = "X";
  }
  document.getElementById("ft").value = results;
}
</script>


  <script type="text/javascript">
function myFunctionHt() {
  var home = document.getElementById("home_ht_score").value;
    var away = document.getElementById("away_ht_score").value;
  var results;
  if (home > away) {
    results = "1";
  } else if (home < away) {
    results = "2";
  }  else if (home = away) {
    results = "X";
  }
  document.getElementById("ht").value = results;
}
</script>

You should use an event listener to update the input value in real-time. I am unable to get what your end-output would look like but understanding from your explanation I believe this is what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM