i want to be able to add a validation to my dropdown lists. If the user was to select cardiff in the first dropdown(select1) and again in the second dropdown(select2) if should give a alert message to the user saying "destination can't be same as the departure".
I know this isn't user friendly but it needs to be done=S
I was getting issues with the second drop down as it doesn't seem to work as a double AND if statement.
Please use jsfiddle.net to help me thanks.
Departure: <br>
<select id="select1">
<option value="" disabled selected>Please Select</option>
<option>Birmingham</option>
<option>Bristol</option>
<option>Cardiff</option>
<option>Liverpool</option>
<option>London</option>
<option>Manchester</option>
</select>
<br><br>
Destination: <br>
<select id="select2">
<option value="" disabled selected>Please Select</option>
<option>Birmingham</option>
<option>Bristol</option>
<option>Cardiff</option>
<option>Liverpool</option>
<option>London</option>
<option>Manchester</option>
</select>
<br><br>
<input type="Button" value="Order Tickets" onClick="myFunction()">
<script>
function myFunction()
{
if (document.getElementById("select1" && "select2").value == "Cardiff")
alert("Destination can't be same as Departure.");
else
alert("That's Fine");
}
</script>
document.getElementById("select1" && "select2")That's equal thandocument.getElementById("select2")ifand orgetElementById."select1" && "select2". What result is? AndgetElementById()it's a method, or a function, call it as you want, and you can`t make an AND statement inside