6

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

2 Answers 2

19
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("");
Sign up to request clarification or add additional context in comments.

2 Comments

I have tried clearing by replacing the value with (""), however, the input field validation is not resetting back to default. Could you please let me know how to deal with that?
@Anand are you using the built-in HTML required validation or something custom?
9

.value is a property, not a function.

You want .value = "";.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.