The process of obtaining ItemCode, ItemName, ItemPrice and Qty from the user, saving them as cookies, and subsequently presenting them on the following webpage can be done as follows:
Create a form on the webpage where the user can input the required information - ItemCode, ItemName, ItemPrice and Qty.
When the user submits the form, use JavaScript to store the values as cookies. This can be done using the document.cookie
property.
To retrieve the values from the cookies on the following webpage, use JavaScript to read the values from the cookies using the document.cookie
property.
Use JavaScript again to display the values on the following webpage. This can be done using the innerHTML
property to modify the HTML content of the page.
Example Code:
HTML for the form on the first page:
<form id="itemForm">
ItemCode: <input type="text" name="itemCode"><br>
ItemName: <input type="text" name="itemName"><br>
ItemPrice: <input type="text" name="itemPrice"><br>
Qty: <input type="number" name="qty"><br>
<input type="submit" value="Submit">
</form>
JavaScript code to store the form data as cookies:
document.getElementById("itemForm").addEventListener("submit", function(event) {
event.preventDefault(); // prevent the form from submitting
// get the form data
var itemCode = document.getElementsByName("itemCode")[0].value;
var itemName = document.getElementsByName("itemName")[0].value;
var itemPrice = document.getElementsByName("itemPrice")[0].value;
var qty = document.getElementsByName("qty")[0].value;
// set the cookies
document.cookie = "itemCode=" + itemCode;
document.cookie = "itemName=" + itemName;
document.cookie = "itemPrice=" + itemPrice;
document.cookie = "qty=" + qty;
});
JavaScript code to display the cookie values on the following webpage:
document.getElementById("itemCode").innerHTML = getCookie("itemCode");
document.getElementById("itemName").innerHTML = getCookie("itemName");
document.getElementById("itemPrice").innerHTML = getCookie("itemPrice");
document.getElementById("qty").innerHTML = getCookie("qty");
function getCookie(name) {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
if (cookie.startsWith(name + "=")) {
return cookie.substring(name.length + 1);
}
}
return "";
}
Note: The above code is just an example and may need to be modified to fit the specific requirements of the project.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-02-01 11:00:00 +0000
Seen: 7 times
Last updated: Apr 15 '22
Is it feasible to utilize a Toggle Button to switch among multiple classes exceeding 2?
What is the process for generating a dynamic subdomain/URL using vue.js?
How can I create a transition on click using CSS without the need for JavaScript?
How can the style of the loader be modified while the form submission is being processed?
I'm attempting to develop a Javascript-based comments section for my website.
What are some feasible methods to enable MIDI file playback on a web browser?