Write a program with html that the name, father's name, national number and date of…
- User
Write a program with html that the name, father's name, national number and date of birth should be in Farsi and take and save the contact number, address, educational qualification and position The database will be displayed It is possible to delete and search in the database Press enter to go to the next field The program environment is in the form of an app
- Assistant
Creating a simple web application that allows users to input personal information in Farsi, save this information, and then provide CRUD (Create, Read, Update, Delete) functionalities with search capability involves several steps. Here's a basic implementation using HTML, CSS, JavaScript, and a mock database using an array to ensure it’s a fully front-end example without a backend server. If using a database like MySQL or MongoDB for real-world scenarios, you'd need a back-end language like Node.js or PHP.
- HTML: Define the structure of the app.
- CSS: Style the application for better user interface design.
- JavaScript: Handle the logic, including saving data, search, and delete functionalities.
HTML (index.html)
<!DOCTYPE html> <html lang="fa"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>برنامه اطلاعات شخصی</title> <link rel="stylesheet" href="styles.css"> </head> <body> <div class="app"> <h1>فرم اطلاعات شخصی</h1> <form id="infoForm"> <label>نام:</label> <input type="text" id="name" required><br> <label>نام پدر:</label> <input type="text" id="fatherName" required><br> <label>کد ملی:</label> <input type="text" id="nationalNumber" required><br> <label>تاریخ تولد:</label> <input type="text" id="birthDate" placeholder="yyyy/mm/dd" required><br> <label>تلفن تماس:</label> <input type="text" id="contactNumber" required><br> <label>آدرس:</label> <input type="text" id="address" required><br> <label>تحصیلات:</label> <input type="text" id="education" required><br> <label>سمت:</label> <input type="text" id="position" required><br> <button type="button" onclick="addEntry()">ذخیره</button> </form> <input type="text" id="searchField" placeholder="جستجو..." onkeyup="searchEntry()"><br> <table id="dataTable"> <thead> <tr> <th>نام</th> <th>نام پدر</th> <th>کد ملی</th> <th>تاریخ تولد</th> <th>تلفن تماس</th> <th>آدرس</th> <th>تحصیلات</th> <th>سمت</th> <th>عملیات</th> </tr> </thead> <tbody> <!-- Entries will be appended here --> </tbody> </table> </div> <script src="script.js"></script> </body> </html>CSS (styles.css)
body { font-family: 'Arial', sans-serif; direction: rtl; background-color: #f4f4f9; margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh; } .app { width: 80%; max-width: 800px; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0,0,0,0.1); } label { margin-bottom: 5px; display: block; } input[type="text"], button { width: 100%; padding: 10px; margin-bottom: 15px; border: 1px solid #ddd; border-radius: 5px; } button { background: #007bff; color: white; cursor: pointer; } button:hover { background: #0056b3; } table { width: 100%; border-collapse: collapse; margin-top: 20px; } th, td { padding: 10px; border: 1px solid #ddd; text-align: left; } th { background: #f9f9f9; } tr:nth-child(even) { background: #f2f2f2; }JavaScript (script.js)
let database = []; function addEntry() { const name = document.getElementById('name').value; const fatherName = document.getElementById('fatherName').value; const nationalNumber = document.getElementById('nationalNumber').value; const birthDate = document.getElementById('birthDate').value; const contactNumber = document.getElementById('contactNumber').value; const address = document.getElementById('address').value; const education = document.getElementById('education').value; const position = document.getElementById('position').value; const entry = { name, fatherName, nationalNumber, birthDate, contactNumber, address, education, position }; database.push(entry); clearForm(); displayEntries(); } function displayEntries() { const dataTable = document.getElementById('dataTable').getElementsByTagName('tbody')[0]; dataTable.innerHTML = ''; // Clear existing entries database.forEach((entry, index) => { const newRow = dataTable.insertRow(); Object.values(entry).forEach(text => { let newCell = newRow.insertCell(); let newText = document.createTextNode(text); newCell.appendChild(newText); }); const deleteCell = newRow.insertCell(); const deleteButton = document.createElement('button'); deleteButton.textContent = 'حذف'; deleteButton.onclick = () => deleteEntry(index); deleteCell.appendChild(deleteButton); }); } function deleteEntry(index) { database.splice(index, 1); displayEntries(); } function clearForm() { document.getElementById('infoForm').reset(); } function searchEntry() { const searchValue = document.getElementById('searchField').value.toLowerCase(); const dataTable = document.getElementById('dataTable').getElementsByTagName('tbody')[0]; dataTable.innerHTML = ''; database.filter(entry => Object.values(entry).some(value => value.toLowerCase().includes(searchValue) ) ).forEach((entry, index) => { const newRow = dataTable.insertRow(); Object.values(entry).forEach(text => { let newCell = newRow.insertCell(); let newText = document.createTextNode(text); newCell.appendChild(newText); }); const deleteCell = newRow.insertCell(); const deleteButton = document.createElement('button'); deleteButton.textContent = 'حذف'; deleteButton.onclick = () => deleteEntry(index); deleteCell.appendChild(deleteButton); }); }Explanation
- HTML: Defines a form for data entry in Farsi and a table for displaying the data.
- CSS: Ensures a good-looking responsive design with basic styling.
- JavaScript: Manages data operations: adding, displaying, deleting, and searching entries within an array.
Note
This example is designed to operate entirely within the browser. For persistent data storage and more detailed operational control, consider integrating a proper back-end server with database management.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.