How to clear asp: TextBox text when user opens popup again?

I follow How to clear a text box using javascript , but my script changes little. I have a login button, and when the user clicks on the login, the popup is open. It fills in the text box and for some reason returns to the main page. When it comes to the login popup again, the previous value will not be cleared. Maybe this is because the page is not loaded. And I do not want to reload the page. I want to use jquery / javascript to remove the entered text. I have an idea that I am writing code inside the Close button, but I don’t know how to clear text fields. Please, help.

Here is the code, the script is that I used popup to login and register. In the pop-up login window there is a link "Do not have a login ID", when the user clicks on it, a pop-up message with a form opens.

<a href="#" id="signUp" onclick="function_deletePreviousData">Don't have Login Id</a> 

And the JavaScript method

 <script type="text/javascript"> function function_deletePreviousData(){ document.getElementById("signUp").value = ""; } </script> 

But nothing happened. I think this is because I do not give the id of the element, I just pass the identifier of the element that I used to register on the popup form. Any idea to clean the entire form without access to all elements and get a null value.

+5
source share
2 answers

Finally, I found a method in jQuery to reset all fields. Only trigger reset.

 $('#form').trigger("reset"); 

Thank you all for your help.

+3
source

Instead of including the code in closing the click button, we should write the code in the login button of the click.This is one of my suggestions.

Try once:

JavaScript:

 <script type="text/javascript"> function LoginButtonClick() { document.getElementById`("TextBox_Id").value = ""; } </script> 

JQuery

 jQuery("#LoginButton_Id").Click( function() { $('#TextBox_Id').val(""); } ); 
+2
source

Source: https://habr.com/ru/post/1242993/


All Articles