Lodder
Lodder

Reputation: 19733

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

Upvotes: 5

Views: 46992

Answers (2)

Zoltan Toth
Zoltan Toth

Reputation: 47667

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("");

Upvotes: 18

SLaks
SLaks

Reputation: 887433

.value is a property, not a function.

You want .value = "";.

Upvotes: 9

Related Questions