Reset input value after alert - Javascript

Lodder picture Lodder · Jun 7, 2012 · Viewed 42.2k times · Source

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

Answer

Zoltan Toth picture Zoltan Toth · Jun 7, 2012
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("");