Trying to figure out a javascript exercise that I can't find the answer to.
Here's my base code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Simple validation</title>
</head>
<body>
<form onsubmit="return validateInput()">
<input type="text" name="txt">
<input type="checkbox" name="chk" id ="check_box">
<input type="radio" name="group" value="Radio A" id="radio_a">
<input type="radio" name="group" value="Radio B" id="radio_b">
<input type="submit"/>
</form>
<!-- Display error message in following div -->
<div class="error-message"></div>
<script type="text/javascript">
function validateInput() {
// function that validates inputs from form and displays the message
}
</script>
</body>
</html>
What I'm trying to do is write the function that does the following things:
The validation should check the following rules: - Rule 1: "chk" may be checked only if "Radio B" is selected. - Rule 2: If "Radio A" is selected, the text box must contain a non-empty string.
Depending on failed rules, an appropriate error message should be displayed in the provided div (class “error-message”): - “RULE 1 FAILED”, - “RULE 2 FAILED”, or - “BOTH RULES FAILED”.
Aucun commentaire:
Enregistrer un commentaire