skip to Main Content

I want determine the value of textbox based on the previous textbox using JavaScript, But the code it’s not work.

Here the result

Here the javascript

  function result_method(){
    var bw_method =document.getElementById("bw_method");
    var w_method = document.getElementById("w_method");
    var result_method = document.getElementById("result_method");

    if (!isNaN(bw_method.value="Accepted", w_method.value="Accepted")){
      document.querySelector('[name="result_method"]').value = "Pass";
      }else{
        document.querySelector('[name="result_method"]').value="Fail";
      }

  }
         <label> Before Wash </label>
            <select name="bw_method" id="bw_method" class="form-control" onkeyup="result_method();" disabled>
                <option selected >PILIH</option>
                <option value="Accepted">Accepted</option>
                <option value="Rejeceted">Rejected</option>
               </select>
           
     
          <label> 1. wash </label>
           <select name="w_method" id="w_method" class="form-control" onkeyup="result_method();">
             <option selected disabled>PILIH</option>
                 <option value="Accepted">Accepted</option>
             <option value="Rejected">Rejected</option>
            </select>
   
        <label> Result </label>
          <input name="result_method" id="result_method" type="text" class="form-control" readonly>  

Please help me, thankyouuuu

2

Answers


  1. I think your javascript function is if the condition syntax is incorrect try to below.

    if (bw_method === "Accepted" && w_method === "Accepted") {
         result_method.value = "Pass";
    } else { 
         result_method.value = "Fail";
     }
    }
    

    Try this one

    Login or Signup to reply.
  2. Please check following working demo, there were issues in condition and its passed values,

    function result_method() {
        let bw_method =document.getElementById("bw_method");
        let w_method = document.getElementById("w_method");
        let result_method = document.getElementById("result_method");
        let result = (bw_method.value === "Accepted" && w_method.value === "Accepted") ? "Pass" : "Fail";
        document.querySelector('[name="result_method"]').value = result;
    }
    <label> Before Wash </label>
    <select name="bw_method" id="bw_method" class="form-control" onchange="result_method();" disabled>
      <option>PILIH</option>
      <option value="Accepted" selected>Accepted</option>
      <option value="Rejeceted">Rejected</option>
     </select>
                   
     <label> 1. wash </label>
     <select name="w_method" id="w_method" class="form-control" onchange="result_method();">
       <option selected disabled>PILIH</option>
           <option value="Accepted">Accepted</option>
       <option value="Rejected">Rejected</option>
      </select>
       
     <label> Result </label>
     <input name="result_method" id="result_method" type="text" class="form-control" readonly>  
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search