I have a simple input box where if the number is higher than 2, a popup message will appear.
Here is the code I am using, however I already have an onkeyup
command on the input for something else, so I hope that won't be a problem
HTML:
<input id="jj_input23" type="text" value='' onkeyup='changeTransform()' />
Javascript:
if(jj_input23 > 2) {
alert("Making the scale higher than 2 will make the preview too big");
document.getElementById('jj_input23').value("");
}
After the aler message has been displayed, and the user has clicked "Ok", I want the input text to reset. How can I do this?
Thanks in advance
reset() The HTMLFormElement. reset() method restores a form element's default values. This method does the same thing as clicking the form's <input type="reset"> control.
To clear an input field after submitting:Add a click event listener to a button. When the button is clicked, set the input field's value to an empty string. Setting the field's value to an empty string resets the input.
<input type="reset"> buttons are used to reset forms. If you want to create a custom button and then customize the behavior using JavaScript, you need to use <input type="button"> , or better still, a <button> element.
if(jj_input23 > 2) {
alert("Making the scale higher than 2 will make the preview too big");
document.getElementById('jj_input23').value = "";
}
If you're using jQuery then you almost got it:
$('#jj_input23').val("");
.value
is a property, not a function.
You want .value = "";
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With