Unable to Validate multiple Inputs
I have a simple 5 input boxes where user can select 5 different cities from Autocomplete. I want to Validate if any user is entering same city name more than once or not. And highlight that box with a color.
I tried with two input boxes it works fine. For more than two it does not work.
html
- <html>
- <input type="text" name="country1" id="country1"/>
- <input type="text" name="country2" id="country2"/>
- <input type="text" name="country3" id="country3"/>
- <input type="text" name="country4" id="country4"/>
- <input type="text" name="country5" id="country5"/>
- <input value="Draw Chart" type="submit" id="submit"/>
- </html>
-
Javscript
- $( function() {
- var availableTags = [
- "London",
- "New York",
- "Tokyo",
- "Manila",
- "Hong Kong",
- "Taipei",
- "New Delhi",
- "Colombo",
- "Dubai",
- "Paris",
- "Berlin",
- "Stockholem",
- "Madrid",
-
- ];
- $( "#country1,#country2,#country3" ).autocomplete({
- source: availableTags
- });
- } );
-
- $("#submit").click(function(){
- // Works for Two Input
- /*if ($('#country1').attr('value') == $('#country2').attr('value')){
- alert("You are not allowed to Select Same city multiple times");
- $("#submit").button("disable");
- return false;
- }*/
- //Does not Work for more than two
- if ($('#country1').attr('value') == $('#country2').attr('value')==('#country3').attr('value')){
- alert("You are not allowed to Select Same city multiple times");
- $("#submit").button("disable");
- return false;
- }