Clear user input after form submission.

hello all
i have this code below to insert data to a database,and two user input text boxes.
when i hit submit, the two text boxes are not cleared out! , how to solve this pleas
thanks

export function submit_form(event, $w) {

//Add your code for this event here:

$w(‘#imgLoader’).show() // “yourGif” refers to preloader gif
setTimeout(() => {
const nameInputValue = $w(‘#nameInput’).value;
const PhoneInputValue = $w(‘#phoneNumber’).value;
const toInsert = {
name: nameInputValue,
phoneno: PhoneInputValue,

} 
wixData.insert('test',toInsert) 
.then(() => { 
  wixLocation.to('thankyoupage') 
}) 

},20); // set the time to preform the insert method. 2000ms
}

Hi Rashid,

When you use code to save data into a collection you will need to manually clear the input boxes.

You can quickly achieve this using the following method:

export function button1_click(event, $w) {
    resetForm();
}

function resetForm() {
 const inputList = $w('TextInput');
    inputList.forEach(element => {
        element.value = '';
    });
}

I am having a similar problem with my music theory testing site build.

The user inputs an answer to a question generated from variables from the database. The user is told their answer is either correct or incorrect, and a “next” button appears to generate the next question on the same page. This all works, however, the user input stays in the text input box.

I tried messing about with the code supplied above but to no avail.

Here is what I have written for my “next” button:

export function button2_click() {
// clear any filters in the dataset
$w(“#dynamicDataset”).setFilter(wixData.filter());

// get size of collection that is connected to the dataset
let count = $w(“#dynamicDataset”).getTotalCount();

// get random number using the size as the maximum
let idx = Math.floor(Math.random() * count);

// set the current item index of the dataset
$w(“#dynamicDataset”).setCurrentItemIndex(idx);

$w("#incorrect").hide(); 
$w("#correct").hide(); 
$w("#answerC").hide(); 
$w("#button2").hide(); 
$w('#input1').placeholder = "What's your answer?"; 

}

You need to set the answer box value to an empty value
$w(’ #input1 ').value = ‘’;

Dammit I tried that but obviously had something wrong because it worked this time. Embarrassingly simple thank you so much

No problem

Hi I have the same problem, but would like to keep the placeholder text in the box, could you tell me where to find the answer box? to set to $w(’ #input1 ').value = ‘’; Thank you Andy