So, I need a function to check if the rules I've made apply to the options I have in my form.
The first box is a name box and it needs to have at least three letters and contain at least one whitespace to pass. The other box is age, it needs to have a number between 1 and 125, I can do that on my own but I'm thinking there might be a nice way to set all of the rules at once so I thought I'd include it.
The third option is a set of three radio buttons of which one has to be selected and the fourth box is an info box that should consist of a text with at least 30 letters. These rules should be checked on the press of a button, this is how far I've gotten on my own:
var sendButton = $("button:first").addClass("sendButton");
var age = document.getElementsByName('age')[0].value;
sendButton.click(function(){
var infoName = document.getElementsByName('infoName')[0].value;
if (infoName.length<3){
console.log("Your name must consist of at least three letters and contain a whitespace");
};
}
});
<section class="column">
<h2>Contact us</h2>
<form action="#">
<fieldset>
<legend>Form</legend>
<div class="textinput">
<label for="infoName">Ditt namn:</label>
<input type="text" name="infoName" placeholder="ex. John Doe">
</div>
<div class="textinput">
<label for="infoName">Din ålder:</label>
<input type="text" name="age" placeholder="ex. 25">
</div>
<div class="radioSelection">
<label>Choose your favorite</label>
<input type="radio" name="favorite" id="html" value="html">
<label for="html">HTML</label>
<input type="radio" name="favorite" id="js" value="js">
<label for="js">JavaScript</label>
<input type="radio" name="favorite" id="css" value="css">
<label for="css">CSS</label>
</div>
<div class="textareainput">
<label for="info">Info about you:</label>
<textarea placeholder="Type something about yourself, this area must contain 30 letters or more"></textarea>
</div>
<div class="action">
<button>Send</button>
</div>