0

I have tried to get it to work but I simply can't find the mistake. Also I have no idea how to make the selection which you have not selected to turn red or some color to alert you.

<!DOCTYPE html>
<html>
    <body>
        <select id='Selection' name='Selection'>
            <option value=''>Select</option>
            <option value='1'>user1</option>
            <option value='2'>user2</option>
            <option value='3'>user3</option>
        </select>
        <br>
        <select id='Candidate' name='Candidate'>
            <option value=''>Select</option>
            <option value='1'>candidate1</option>
            <option value='2'>candidate2</option>
            <option value='3'>candidate3</option>
        </select>  
        <br>  
        <input type='button' onclick='Validate()' value='select' />
        <script>
            function Validate()
            {
              if(document.getElementById('Selection').value == '' ||
                 document.getElementById('Candidate').value == '' ||)                
              {
                alert('Please complete all selections');
                return false;
              }
              return true;
            }       
        </script>
    </body>
</html>
1
  • fyi, you removed both || operators in your edit, you still need the first one. Commented Mar 12, 2013 at 20:18

1 Answer 1

1

You have an extra || in you if condition, this will cause a syntax error, remove it (the last one not both). To change the element that has an invalid value you can just use css but you'll have to check them individually.

Sign up to request clarification or add additional context in comments.

2 Comments

But how to turn the unselected selection red or sth?
@user1794625 you can set its style e.g. document.getElementById('Candidate').style.border = 'red'; or what ever style want to set.

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.