Here's the form code that I have:
<form id="sizePicker">
Grid Height:
<input type="number" id="inputHeight" name="height" min="1" value="1">
Grid Width:
<input type="number" id="inputWidth" name="width" min="1" value="1">
<input type="submit">
</form>
I need to validate those inputs using a separate JS file:
function getGridValues() {
const inputHeight = document.getElementById('inputHeight').value;
const inputWidth = document.getElementById('inputWidth').value;
const colorPicker = document.getElementById('colorPicker').value;
console.log(`Height: ${inputHeight}, Width: ${inputWidth}, Color: ${colorPicker}`);
}
document.getElementById('submit').addEventListener("click", getGridValues());
The problem is that every time that I click on submit it reloads the page and sends the default values. If I change the values without submitting, I'm able to retrieve those new values using the JS Console.
I've researched a lot on this thing but everything suggests jQuery/Ajax solutions but I'm just allowed to work with HTML/CSS/JS.
What is the problem? How can I fix it?
Thank you in advanced.