JS related to enter button information

I have a lot of new in JS and html, so I'm sorry in advance if you find this question is too primitive.

I am trying to make a simple login page. I manage to switch between the two displays (once logged in or logged out), but I still have one problem: how can I "delete" the username + password from the last login session when I click "logout" ?

In other words, how can I set the input types โ€œpasswordโ€ and โ€œtextโ€ so that they are clear (without any information inside them) using Java Script, preferably with jQuery ?

+4
source share
3 answers
$(document).ready(function(){ $('#username').val("") $('#password').val("") }) 

This should clear both of your logins each time you load a page.

But, as Ibu said, you have to handle logins with the Php server.

+2
source

If you want to clear all input text, just use a simple script like:

 $("input[type=text]").val(''); 

Passing all input with type text will be empty.

You can associate this with the cancel button or even after submitting the form with the confirmation button.

Binding with an example of a cancel button (you will need a button with the identifier = "cancel" for this to work):

 $("#cancel").click(function() { $("input[type=text]").val(''); }); 
0
source

Other answers are good ... using .val('') will do the trick.

I am going to go a little further than what you are asking for, as this may be useful to you and other readers. Here's a general view of the reset function ...

 function resetForm(formId) { $(':input', $('#' + formId)).each(function() { var type = this.type; var tag = this.tagName.toLowerCase(); // normalize case if (type == 'text' || type == 'password' || tag == 'textarea') { // it ok to reset the value attr of text inputs, password inputs, and textareas this.value = ""; } else if (type == 'checkbox' || type == 'radio') { // checkboxes and radios need to have their checked state cleared but should *not* have their 'value' changed this.checked = false; } else if (tag == 'select') { // select elements need to have their 'selectedIndex' property set to -1 (this works for both single and multiple select elements) this.selectedIndex = -1; } }); }; 

Hope this helps.

0
source

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


All Articles