#194 - To-do List v0.1
Create a fully functional to-do list that saves to Memberstack, with add, complete, and delete functionality.
<!-- 💙 MEMBERSCRIPT #194 v0.1 💙 - TO-DO LIST -->
<script>
(function() {
'use strict';
// CONFIGURATION - Change these values to customize
const CONFIG = {
// Change this to match your Data Table name in Memberstack
TABLE_NAME: 'todos',
// Change these selectors if you use different data-ms-code attributes
SELECTORS: {
container: '[data-ms-code="todo-container"]',
form: '[data-ms-code="todo-form"]',
input: '[data-ms-code="todo-input"]',
addButton: '[data-ms-code="todo-add-button"]',
list: '[data-ms-code="todo-list"]',
empty: '[data-ms-code="todo-empty"]',
template: '[data-ms-code="todo-item-template"]',
deleteModal: '[data-ms-code="todo-delete-modal"]',
deleteConfirm: '[data-ms-code="todo-delete-confirm"]',
deleteCancel: '[data-ms-code="todo-delete-cancel"]'
}
};
let memberstack = null;
let currentMember = null;
let pendingDeleteTaskId = null;
// TIMING - Adjust timeout values if needed (in milliseconds)
function waitFor(condition, timeout = 5000) {
return new Promise((resolve) => {
if (condition()) return resolve();
const interval = setInterval(() => {
if (condition()) {
clearInterval(interval);
resolve();
}
}, 100); // Check every 100ms
setTimeout(() => {
clearInterval(interval);
resolve();
}, timeout);
});
}
async function init() {
await Promise.all([
waitFor(() => document.querySelector(CONFIG.SELECTORS.form) && window.$memberstackDom),
waitFor(() => window.$memberstackDom, 10000)
]);
memberstack = window.$memberstackDom;
if (!memberstack) return;
const memberResult = await memberstack.getCurrentMember();
currentMember = memberResult?.data || memberResult;
if (!currentMember?.id) {
// CUSTOMIZE - Change the "not logged in" message here
const container = document.querySelector(CONFIG.SELECTORS.container);
if (container) container.innerHTML = '<div data-ms-code="todo-empty"><p>Please log in to use the to-do list.</p></div>';
return;
}
const form = document.querySelector(CONFIG.SELECTORS.form);
if (form) {
const formClone = form.cloneNode(true);
form.parentNode.replaceChild(formClone, form);
formClone.addEventListener('submit', handleAddTask);
// Also handle click on add button (works even if button is not type="submit")
const addButton = formClone.querySelector(CONFIG.SELECTORS.addButton) || document.querySelector(CONFIG.SELECTORS.addButton);
if (addButton) {
addButton.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
// Trigger form submit event so handleAddTask is called
const submitEvent = new Event('submit', { bubbles: true, cancelable: true });
formClone.dispatchEvent(submitEvent);
});
}
}
document.querySelector(CONFIG.SELECTORS.deleteConfirm)?.addEventListener('click', (e) => {
e.preventDefault();
handleConfirmDelete();
});
document.querySelector(CONFIG.SELECTORS.deleteCancel)?.addEventListener('click', (e) => {
e.preventDefault();
const modal = document.querySelector(CONFIG.SELECTORS.deleteModal);
if (modal) {
modal.style.display = 'none';
pendingDeleteTaskId = null;
}
});
const modal = document.querySelector(CONFIG.SELECTORS.deleteModal);
if (modal) modal.style.display = 'none';
await loadTasks();
}
async function loadTasks() {
if (!memberstack || !currentMember?.id) return;
try {
const result = await memberstack.queryDataRecords({
table: CONFIG.TABLE_NAME,
query: {
where: { member: { equals: currentMember.id } },
orderBy: { created_at: 'desc' }, // SORTING - Change 'desc' to 'asc' for oldest first
take: 100 // LIMIT - Change max number of tasks to load
}
});
const list = document.querySelector(CONFIG.SELECTORS.list);
const empty = document.querySelector(CONFIG.SELECTORS.empty);
const template = document.querySelector(CONFIG.SELECTORS.template);
if (!list) return;
const templateClone = template && template.parentElement === list ? template.cloneNode(true) : null;
list.innerHTML = '';
if (templateClone) list.appendChild(templateClone);
const tasks = result?.data?.records || result?.data || result || [];
if (tasks.length === 0) {
if (empty) empty.style.display = 'block';
return;
}
if (empty) empty.style.display = 'none';
tasks.forEach(task => renderTask(task));
} catch (error) {
console.error('MemberScript #194: Error loading tasks:', error);
const empty = document.querySelector(CONFIG.SELECTORS.empty);
if (empty) empty.style.display = 'block';
}
}
function renderTask(task) {
const list = document.querySelector(CONFIG.SELECTORS.list);
const template = document.querySelector(CONFIG.SELECTORS.template);
if (!list || !template) return;
const taskItem = template.cloneNode(true);
const taskData = task.data || {};
const isCompleted = taskData.completed === true;
taskItem.removeAttribute('data-ms-code');
taskItem.setAttribute('data-ms-code', 'todo-item');
taskItem.setAttribute('data-task-id', task.id);
taskItem.classList.remove('todo-template-hidden');
taskItem.style.display = '';
const checkbox = taskItem.querySelector('[data-ms-code="todo-checkbox"]');
const taskTextEl = taskItem.querySelector('[data-ms-code="todo-text"]');
const deleteBtn = taskItem.querySelector('[data-ms-code="todo-delete"]');
if (checkbox) {
checkbox.checked = isCompleted;
checkbox.addEventListener('change', (e) => {
handleToggleTask(task.id, e.target.checked);
});
}
if (taskTextEl) {
taskTextEl.textContent = taskData.task || '';
if (isCompleted) {
taskTextEl.classList.add('completed');
}
}
if (deleteBtn) {
deleteBtn.addEventListener('click', (e) => {
e.preventDefault();
handleDeleteTask(task.id);
});
}
list.insertBefore(taskItem, list.firstChild);
}
async function handleAddTask(event) {
event.preventDefault();
const input = event.target.querySelector(CONFIG.SELECTORS.input) || document.querySelector(CONFIG.SELECTORS.input);
if (!input) return;
const taskText = input.value.trim();
if (!taskText) return;
const addButton = document.querySelector(CONFIG.SELECTORS.addButton);
if (addButton) {
addButton.disabled = true;
addButton.textContent = 'Adding...'; // BUTTON TEXT - Change loading state text
}
try {
const now = new Date().toISOString();
// TASK DATA - Add or modify fields here to match your Data Table schema
const taskData = {
task: taskText,
completed: false,
member: currentMember.id,
created_at: now,
updated_at: now
};
try {
await memberstack.createDataRecord({ table: CONFIG.TABLE_NAME, data: taskData });
} catch (e) {
await memberstack.createDataRecord({
table: CONFIG.TABLE_NAME,
data: { ...taskData, member: { id: currentMember.id } }
});
}
input.value = '';
await loadTasks();
} catch (error) {
console.error('MemberScript #194: Error adding task:', error);
// ERROR MESSAGE - Customize the error message shown to users
alert('Failed to add task. Please try again.');
} finally {
if (addButton) {
addButton.disabled = false;
addButton.textContent = 'Add'; // BUTTON TEXT - Change button text
}
}
}
async function handleToggleTask(taskId, newCompletedState) {
try {
await memberstack.updateDataRecord({
recordId: taskId,
data: { completed: newCompletedState, updated_at: new Date().toISOString() }
});
// Update UI immediately
const taskItem = document.querySelector(`[data-task-id="${taskId}"]`);
if (taskItem) {
const taskTextEl = taskItem.querySelector('[data-ms-code="todo-text"]');
const checkbox = taskItem.querySelector('[data-ms-code="todo-checkbox"]');
if (taskTextEl) {
if (newCompletedState) {
taskTextEl.classList.add('completed');
} else {
taskTextEl.classList.remove('completed');
}
}
if (checkbox) {
checkbox.checked = newCompletedState;
}
}
} catch (error) {
console.error('MemberScript #194: Error toggling task:', error);
await loadTasks();
}
}
function handleDeleteTask(taskId) {
pendingDeleteTaskId = taskId;
const modal = document.querySelector(CONFIG.SELECTORS.deleteModal);
if (modal) modal.style.display = 'flex';
}
async function handleConfirmDelete() {
if (!pendingDeleteTaskId) return;
const taskId = pendingDeleteTaskId;
pendingDeleteTaskId = null;
const modal = document.querySelector(CONFIG.SELECTORS.deleteModal);
if (modal) modal.style.display = 'none';
try {
await memberstack.deleteDataRecord({ recordId: taskId });
const taskItem = document.querySelector(`[data-task-id="${taskId}"]`);
if (taskItem) taskItem.remove();
const list = document.querySelector(CONFIG.SELECTORS.list);
const taskItems = list ? Array.from(list.children).filter(c => c.getAttribute('data-ms-code') !== 'todo-item-template') : [];
if (taskItems.length === 0) {
const empty = document.querySelector(CONFIG.SELECTORS.empty);
if (empty) empty.style.display = 'block';
}
} catch (error) {
console.error('MemberScript #194: Error deleting task:', error);
// ERROR MESSAGE - Customize the error message shown to users
alert('Failed to delete task. Please try again.');
await loadTasks();
}
}
// INITIALIZATION DELAY - Adjust the 100ms delay if scripts load slowly
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => setTimeout(init, 100));
} else {
setTimeout(init, 100);
}
})();
</script>
Customer Showcase
Have you used a Memberscript in your project? We’d love to highlight your work and share it with the community!
Creating the Make.com Scenario
1. Download the JSON blueprint below to get stated.
2. Navigate to Make.com and Create a New Scenario...

3. Click the small box with 3 dots and then Import Blueprint...

4. Upload your file and voila! You're ready to link your own accounts.
Need help with this MemberScript?
All Memberstack customers can ask for assistance in the 2.0 Slack. Please note that these are not official features and support cannot be guaranteed.
Join the 2.0 SlackAuth & payments for Webflow sites
Add logins, subscriptions, gated content, and more to your Webflow site - easy, and fully customizable.
.webp)
"We've been using Memberstack for a long time, and it has helped us achieve things we would have never thought possible using Webflow. It's allowed us to build platforms with great depth and functionality and the team behind it has always been super helpful and receptive to feedback"

"Been building a membership site with Memberstack and Jetboost for a client. Feels like magic building with these tools. As someone who’s worked in an agency where some of these apps were coded from scratch, I finally get the hype now. This is a lot faster and a lot cheaper."

"One of the best products to start a membership site - I like the ease of use of Memberstack. I was able to my membership site up and running within a day. Doesn't get easier than that. Also provides the functionality I need to make the user experience more custom."

"My business wouldn't be what it is without Memberstack. If you think $30/month is expensive, try hiring a developer to integrate custom recommendations into your site for that price. Incredibly flexible set of tools for those willing to put in some minimal efforts to watch their well put together documentation."


"The Slack community is one of the most active I've seen and fellow customers are willing to jump in to answer questions and offer solutions. I've done in-depth evaluations of alternative tools and we always come back to Memberstack - save yourself the time and give it a shot."

Need help with this MemberScript? Join our Slack community!
Join the Memberstack community Slack and ask away! Expect a prompt reply from a team member, a Memberstack expert, or a fellow community member.
Join our Slack
.png)