Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset input value after alert - Javascript

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

like image 663
Lodder Avatar asked Jun 06 '12 23:06

Lodder


People also ask

How to reset input in js?

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.

How do you clear the input field value in JavaScript after submit?

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.

How do you write a reset function in JavaScript?

<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.


2 Answers

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("");
like image 188
Zoltan Toth Avatar answered Sep 27 '22 20:09

Zoltan Toth


.value is a property, not a function.

You want .value = "";.

like image 42
SLaks Avatar answered Sep 27 '22 20:09

SLaks