In: Computer Science
In html create a Watchlist page in which a user can create as
many watchlist as they wish. This page will contain the list
of
watchlist, allow the user to create a new watchlist, and delete an
existing one.
You have to implement the following:
a) A list of all the watchlist that a user has created. For now,
you can randomly
create few.
b) An option to create a new watchlist. Make sure you ask the user
what the new
watchlist should be named.
c) An option to delete a particular watchlist.
We have to use JavaScript for this because you cant perform these actions using HTML only. For that we have to prepare a HTML Layout wich contains the following:
<!DOCTYPE html>
<html>
<head>
<title>Watchlists</title>
</head>
<body>
<UL id="watchlist_list">
<LI>Watchlish 1 <button onclick="delete_watchlist(this)">x</button></LI>
<LI>Watchlish 2 <button onclick="delete_watchlist(this)">x</button></LI>
<LI>Watchlish 3 <button onclick="delete_watchlist(this)">x</button></LI>
<LI>Watchlish 4 <button onclick="delete_watchlist(this)">x</button></LI>
<LI>Watchlish 5 <button onclick="delete_watchlist(this)">x</button></LI>
</UL>
<input type="text" name="watchlist_name" id="watchlist_name"/>
<button id="create" onclick="add_watchlist()">Create watchlist</button>
</body>
</html>
As you can see I have called delete_watchlist() and add_watchlist() for functionalities. below is the implementation of that two functions in Javascript you can add those fuctions using script tag or keep them saperated using an external javascript file.
Function for add and delete watchlist:
var element_div = document.getElementById('watchlist_list');
function add_watchlist() {
var watchlist_name = document.getElementById('watchlist_name').value;
element_div.innerHTML += "<LI>"+watchlist_name
+ ' <button onclick="delete_watchlist(this)">x</button></LI>';
document.getElementById('watchlist_name').value = "";
}
function delete_watchlist(event)
{
event.parentNode.parentNode.removeChild(event.parentNode);
}