if (shape === 'circle') {
newButton.style.borderRadius = '50%';
}
document.body.appendChild(newButton);
// Save button data to the server using AJAX
saveButtonData(newButton, shape);
// Add event listener for button deletion
newButton.addEventListener('click', function() {
deleteButton(this);
});
function deleteButton(button) {
const url = 'deleteButton.php';
const data = JSON.stringify({
buttonName: button.innerHTML,
});
ajaxRequest('POST', url, data, function(response) {
if (response.success) {
// Remove the button from the DOM
button.remove();
} else {
console.error('Error deleting button:', response.error);
}
});
if (shape === 'circle') {
newButton.style.borderRadius = '50%';
}
document.body.appendChild(newButton);
// Save button data to the server using AJAX
saveButtonData(newButton, shape);
// Add event listener for button deletion
newButton.addEventListener('click', function() {
deleteButton(this);
});
function deleteButton(button) {
const url = 'deleteButton.php';
const data = JSON.stringify({
buttonName: button.innerHTML,
});
ajaxRequest('POST', url, data, function(response) {
if (response.success) {
// Remove the button from the DOM
button.remove();
// Update buttonCount based on the existing buttons
buttonCount = document.querySelectorAll('.button').length;
} else {
console.error('Error deleting button:', response.error);
}
});
HTML [
<!DOCTYPE html>
]
JS [
let buttonCount = 0; const xhr = new XMLHttpRequest();
function createButton(shape) { const newButton = document.createElement('button'); newButton.className = 'button'; newButton.innerHTML =
Button ${++buttonCount}
;}
function ajaxRequest(method, url, data, callback) { xhr.open(method, url, true); xhr.setRequestHeader('Content-type', 'application/json');
}
function saveButtonData(button, shape) { const positionX = button.offsetLeft; const positionY = button.offsetTop; const buttonName = button.innerHTML;
}
function deleteButton(button) { const url = 'deleteButton.php'; const data = JSON.stringify({ buttonName: button.innerHTML, });
}
]
Php: position
[
<?php $data = json_decode(file_get_contents('php://input'), true);
$servername = "your_server_name"; $username = "your_username"; $password = "your_password"; $dbname = "your_database_name";
try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) { echo json_encode(['success' => false, 'error' => $e->getMessage()]); }
$conn = null; ?>
]
Php: delete
[
<?php $data = json_decode(file_get_contents('php://input'), true);
$servername = "your_server_name"; $username = "your_username"; $password = "your_password"; $dbname = "your_database_name";
try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) { echo json_encode(['success' => false, 'error' => $e->getMessage()]); }
$conn = null; ?>
Delete button sequence:
[
let buttonCount = 0; const xhr = new XMLHttpRequest();
function createButton(shape) { const newButton = document.createElement('button'); newButton.className = 'button'; newButton.innerHTML =
Button ${++buttonCount}
;}
function ajaxRequest(method, url, data, callback) { xhr.open(method, url, true); xhr.setRequestHeader('Content-type', 'application/json');
}
function saveButtonData(button, shape) { const positionX = button.offsetLeft; const positionY = button.offsetTop; const buttonName = button.innerHTML;
}
function deleteButton(button) { const url = 'deleteButton.php'; const data = JSON.stringify({ buttonName: button.innerHTML, });
}
]
]