I m triing to build a website for my work
i want to connect number input to search in CMS data collection
i tried with chatGPT and helped my with coding with no errors
but on preview I didn’t get any results
Any one Can Help ???
import wixData from ‘wix-data’;
$w.onReady(function () {
// Add an event handler for the button click
$w(“#searchkey”).onClick(() => {
// Get the value from the text input
let inputValue = $w(“#certnum”).value;
console.log("#certnum", inputValue);
// Query the CMS collection based on the input value
wixData.query("ResultsVarification")
.eq("certificateId", inputValue) // Removed the # from the field name
.find()
.then(results => {
console.log("#resultbox", results);
// Check if there are any matching results
if (results.items.length > 0) {
// Display the data in the text box
let matchingItem = results.items[0];
$w("#nameresult").text = matchingItem.title;
$w("#courseresult").text = matchingItem.itemPageText;
$w("#issueresult").text = matchingItem.altText;
$w("#renewresult").text = matchingItem.dateForUpdateExpiry;
} else {
// Handle the case where no matching data is found
$w("#nameresult").text = "Check";
$w("#courseresult").text = "Entered";
$w("#issueresult").text = "Certificate";
$w("#renewresult").text = "No matching data found";
}
})
.catch(err => {
console.error(err);
});
});
// Add an event handler for the reset button click
$w("#resetkey").onClick(() => {
// Call the function to reset text fields
resetTextFields();
});
});
// Function to reset text fields
function resetTextFields() {
$w(“#certnum”).value = “”; // Clear the text input
$w(“#nameresult”).text = “”;
$w(“#courseresult”).text = “”;
$w(“#issueresult”).text = “”;
$w(“#renewresult”).text = “”;
}