<html> <head> <title>Product Lookup Program</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> </head> <body> <div class="container"> <h1 class="mt-4">Product Lookup Program</h1> <form id="productForm" class="mt-4"> <div class="mb-3"> <label for="productName" class="form-label">Product Name</label> <input type="text" class="form-control" id="productName" required> </div> <div class="mb-3"> <label for="productPrice" class="form-label">Product Price</label> <input type="number" class="form-control" id="productPrice" required> </div> <button type="submit" class="btn btn-primary">Save Product</button> </form> <div id="productList" class="mt-4"> <h3>Product List</h3> <table class="table"> <thead> <tr> <th scope="col">#</th> <th scope="col">Product Name</th> <th scope="col">Product Price</th> <th scope="col">Actions</th> </tr> </thead> <tbody id="productTableBody"> <!-- Product Table Rows will be dynamically added here --> </tbody> </table> </div> <div id="searchProduct" class="mt-4"> <h3>Search Product</h3> <div class="mb-3"> <label for="searchProductName" class="form-label">Product Name</label> <input type="text" class="form-control" id="searchProductName" required> </div> <button type="button" class="btn btn-primary" onclick="searchProduct()">Search</button> </div> <div id="searchResult" class="mt-4"> <h3>Search Result</h3> <p id="searchResultPrice"></p> </div> </div> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script> <script> // Array to store the products let products = []; // Function to render the product list function renderProductList() { const productList = document.getElementById("productTableBody"); productList.innerHTML = ""; products.forEach((product, index) => { const row = document.createElement("tr"); row.innerHTML = ` <th scope="row">${index + 1}</th> <td>${product.name}</td> <td>${product.price}</td> <td> <button class="btn btn-sm btn-primary" onclick="editProduct(${index})">Edit</button> <button class="btn btn-sm btn-danger" onclick="deleteProduct(${index})">Delete</button> </td> `; productList.appendChild(row); }); } // Function to add a new product function addProduct(event) { event.preventDefault(); const productName = document.getElementById("productName").value; const productPrice = document.getElementById("productPrice").value; products.push({ name: productName, price: productPrice }); renderProductList(); document.getElementById("productForm").reset(); } // Function to edit a product function editProduct(index) { const productName = prompt("Enter the new name for the product"); const productPrice = prompt("Enter the new price for the product"); if (productName && productPrice) { products[index].name = productName; products[index].price = productPrice; renderProductList(); } } // Function to delete a product function deleteProduct(index) { const confirmDelete = confirm("Are you sure you want to delete this product?"); if (confirmDelete) { products.splice(index, 1); renderProductList(); } } // Function to search for a product function searchProduct() { const searchProductName = document.getElementById("searchProductName").value; const searchResultPrice = document.getElementById("searchResultPrice"); const product = products.find(product => product.name.toLowerCase() === searchProductName.toLowerCase()); if (product) { searchResultPrice.textContent = `Price: ${product.price}`; } else { searchResultPrice.textContent = "Product not found"; } } // Add form submission event listener document.getElementById("productForm").addEventListener("submit", addProduct); </script> </body> </html>
Write, Run & Share HTML code online using OneCompiler's HTML online Code editor for free. It's one of the robust, feature-rich online Code editor for HTML language, running on the latest version HTML5. Getting started with the OneCompiler's HTML compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as HTML
. You can also specify the stylesheet information in styles.css
tab and scripts information in scripts.js
tab and start coding.
HTML(Hyper Text Markup language) is the standard markup language for Web pages, was created by Berners-Lee in the year 1991. Almost every web page over internet might be using HTML.
<!DOCTYPE html>
<html>
and ends with </html>
<h1>
to <h6>
where <h1>
is the highest important heading and <h6>
is the least important sub-heading.<p>..</p>
tag.<a>
tag.
<a href="https://onecompiler.com/html">HTML online compiler</a>
<img>
tag, where src
attribute consists of image name.<button>..</button>
tag<ul>
for unordered/bullet list and <ol>
for ordered/number list, and the list items are defined in <li>
.<a href="https://onecompiler.com/html">HTML online compiler</a>
CSS(cascading style sheets) describes how HTML elements will look on the web page like color, font-style, font-size, background color etc.
Below is a sample style sheet which displays heading in green and in Candara font with padding space of 25px.
body{
padding: 25px;
}
.title {
color: #228B22;
font-family: Candara;
}
<table>
tag.<tr>
tag<th>
tag<td>
tag<caption>
tag<script>
is the tag used to write scripts in HTML<script src="script.js"></script>