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>
1
  • It looks like you are using selectedIndex incorrectly. Perhaps this answer can shed some light? stackoverflow.com/a/1085810/7742642 Commented Jul 16, 2021 at 21:31

1 Answer 1

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")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.