0

Hi I have simple fix that is needed. This validation is not working though all other validation works on the page.

   if ((document.getElementById("Authorizing_Company").value == "") && (document.getElementById("Authorizing_Title").selectedIndex == "Other Individual having knowledge of the affairs of the Corporation"))
     {
    alert(Authorizing_Company_msg);
    Authorizing_Company.select();
    Authorizing_Company.focus();
    return(false);              
    }

My HTML

<div class="col-md-6 mb-3">
        <label for="Authorizing_Title">Authorizing Person Position:</label>
      <select name="Authorizing_Title" id="Authorizing_Title" class="form-control form-elements firmnametoggle">
                    <option selected value="">--Select--</option>                         
                    <option value="Current Director">Current Director</option>                
                    <option value="Current Officer">Current Officer</option>                
                    <option value="Other Individual having knowledge of the affairs of the Corporation">Other Individual having knowledge of the affairs of the Corporation</option>                      
                 </select>
  </div>

<div class="col-md-6 mb-3" id="firmname">
        <label for="Authorizing_Company">*Name of Firm or Company:</label>
          <input name="Authorizing_Company" type="text" value="" class="form-control form-elements" id="Authorizing_Company" maxlength="255">
    </div>
Jeff P
  • 51
  • 1
  • 9
  • It looks like you are using `selectedIndex` incorrectly. Perhaps this answer can shed some light? https://stackoverflow.com/a/1085810/7742642 – Simon K Jul 16 '21 at 21:31

1 Answers1

2

This is a logic issue.The problem is on this line of code

(document.getElementById("Authorizing_Title").selectedIndex == "Other Individual having knowledge of the affairs of the Corporation")

In this line of code you try to compare the index of the option which is an integer to a line of string. Therefore is will always be false.

To fix this you can either get the value of the option or just compare with the index.

(document.getElementById("Authorizing_Title").selectedIndex == 3)

OR

(document.getElementById("Authorizing_Title").value== "Other Individual having knowledge of the affairs of the Corporation")
Eric C
  • 19
  • 1