0

I want to validate my drop down list to current javascript function.

Javascript

function theteam() {
    document.add_team_frm.action = "team.php";
    document.add_team_frm.submit();
}

HTML

<form name="add_team_frm" action="team.php" method="post">
<select name="team_name[]">
<option value="0">Select Team</option>
<option value="1">Team A</option>
<option value="2">Team B</option>
<option value="3">Team C</option>
</select>
<a href="javascript:theteam()">Submit Team</a>
</form>

I use link as submit button. How do I add a a validation on name="team_name[]" to the theteam() if value = 0

Let me know.

1 Answer 1

3

try this:

function theteam(){

   //check select
   if(document.getElementById('selectID').value == 'whatever'){
        document.forms['add_team_frm'].submit();
   }
   else { /*select check failed*/ }

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

1 Comment

Worth noting you'll need to amend your HTML above to include an id='selectID' along with the name in your select for this to work...

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.