Not clearing auto-filled input fields after form submission

Hi :slight_smile: I’m working with auto-filled input fields that retrieves information such as the current logged in user’s name and ID from a different database, so that when they go to submit to another database, they don’t need to reinput identifying information. This is very helpful with databases made to have multiple entries from the same user (such as their inventory of items).
The auto-fill works like a charm BUT when it comes to submitting the form, the auto-filled input fields are cleared along with the rest of the fields. I want all non-auto-filled fields to be cleared, but I need the auto-filled fields to retain their information so that the user doesn’t need to reload the page to make another database submission.
How would I go about retaining the auto-filled fields information even after form submission?
Here is the code for the auto-filled fields if it helps:

$w.onReady(function () {
    $w('#dataset2').onReady(() => {
    $w('#dataset1').onReady(() => {
        $w("#input1").value = $w("#dataset1").getCurrentItem().fname;
        $w('#dataset2').setFieldValue('fname',$w('#input1').value);
    })
    })
})

I’ve tried doing onAfterSave functions to get it to keep the info, but nothing I’ve tried has worked so far. Would appreciate any insight!

Thank you :slight_smile:

Try this one…

$w.onReady(function() {
    $w('#dataset1').onReady(()=> {
        $w("#input1").value = $w("#dataset1").getCurrentItem().fname;        
    });

    $w('#dataset2').onReady(() => {
        $w('#dataset2').setFieldValue('fname',$w('#input1').value);
        $w('#dataset2').save();
    });    
});

And also take a look at this one, if you are using Wix-Forms…

…and this one…

And i also ask myself → where is your SUBMIT-BUTTON-CLICK in the code?

Thanks for the quick response. I will give that a go :slight_smile:

Yeah I tried it out, and it doesn’t work unfortunately. Instead, it seems to remove the field value from the database I am getting the auto-fill information from.

@ellezaliajade

Another try…

$w.onReady(function() {
    let fName, title, ID;
    
    $w('#dataset1').onReady(()=> {
        fName = $w("#dataset1").getCurrentItem().fname;
        title = $w("#dataset1").getCurrentItem().title;
        ID = $w("#dataset1").getCurrentItem()._id;
        $w("#input1").value = fName;
        $w('#dataset2').onReady(()=> { 
           $w('#dataset2').setFieldValue('fname', $w('#input1').value);
           $w('#dataset2').save();
        });
    });    
    $w("#dataset2").onAfterSave(()=> {
       console.log("After save ---> "+fName):
       $w("#input1").value = fName;
       console.log("Title: ", title);
       console.log("ID: ", ID);
    });
});

And you still didn’t say anything about → if you are using a custom form, or a Wix-Form!

BTW: And next time let your HELPER know about already similar post, or posts which are involved or related to your ISSUE.
This can save time and headaches!

Oh okay, noted, thanks! Quite sure I am using custom form since I created the database and am using input fields added from the menu and not a premade wix form. Pretty new at al this.
On the note for the relevant issue, I went and tried the second code your suggested, it didn’t work either unfortunately. However I managed to find an alterative way of approaching the task which seems to be working fine (to do with lightboxes for input fields), so I will leave it at that. Thanks for your help regardless :slight_smile: