0

I need the textarea to be filled when "Other" is selected. This is what I have, I thought it will work. But nothing shows up when other is selected and textarea is left blank.

html:

<form onsubmit="return validation()">
<span>Reason for inquiry: <span>
    <select style="color:black" name="reasons">
        <option value="catering">Catering</option>
        <option value="private party">Private Party</option>
        <option value="feedback">Feedback</option>
        <option id="selectedOther" value="other">Other</option>
    </select>
</form>

JS:

function validation(){
    otherInquiry()
}

function otherInquiry(){
    var x = document.getElementById("selectedOther").value;
        if (document.getElementsByTagName("select") == x){
            if(document.getElementById("txtArea").value == ""){
                alert("Please tell us your reason of inquiry")
            }
        return false;
        }
}
FeCH
  • 133
  • 3
  • 15
  • 3
    `getElementsByTagName` returns a **list** of nodes. `x` is a **string**. Comparing a list against a string will always be `false`. Maybe you want to take a look at [Get selected value in dropdown list using JavaScript?](http://stackoverflow.com/q/1085801/218196) – Felix Kling Dec 29 '16 at 00:19
  • Thanks, that fix the issue. – FeCH Dec 29 '16 at 00:30

0 Answers0