Lite mode. Switch to Full
invert_colors
logout
/tech/
/tech/
Post a Replyarrow_backarrow_downward
GermanyHelpBernd2023-12-08 19:18:54 · 3yNo. 295739reply
Why does'nt this HTML, CSS and Javascript-code work?
"<!DOCTYPE html>
<html lang="en">
 
<head>
<meta charset="UTF-8">
<meta name="viewport" contect="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
 
<style>
.demo-list-control {
width: 300px;
}
 
.page-content {padding: 0px 100px;}
</style>
 
<script>
function addTodo(){
todolist.innerHTML = `
<li class="mdl-list__item">
<span class="mdl-list__item-primary-content">
<i class="material-icons mdl-list__item-avatar">label</i>
Todo1
</span>
<span class="mdl-list__item-secondary-action">
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="list-checkbox-1">
<input type="checkbox" id="list-checkbox-1" class="mdl-checkbox__input" checked />
</label>
</span>
</li>
`;
}
</script>
</head>
 
<body>
<!-- Always shows a header, even in smaller screens. -->
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
<header class="mdl-layout__header">
<div class="mdl-layout__header-row">
<!-- Title -->
<span class="mdl-layout-title">To Do Liste</span>
<!-- Add spacer, to align navigation to the right -->
<div class="mdl-layout-spacer"></div>
<!-- Navigation. We hide it in small screens. -->
<nav class="mdl-navigation mdl-layout--large-screen-only">
<a class="mdl-navigation__link" href="">Link</a>
<a class="mdl-navigation__link" href="">Link</a>
<a class="mdl-navigation__link" href="">Link</a>
<a class="mdl-navigation__link" href="">Link</a>
</nav>
</div>
</header>
<div class="mdl-layout__drawer">
<span class="mdl-layout-title">To Do Liste</span>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="">Link</a>
<a class="mdl-navigation__link" href="">Link</a>
<a class="mdl-navigation__link" href="">Link</a>
<a class="mdl-navigation__link" href="">Link</a>
</nav>
</div>
<main class="mdl-layout__content">
<div class="page-content"><!-- Your content goes here -->
 
<form onsubmit="addTodo()">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="todofield">
<label class="mdl-textfield__label" for="todofield">To Do einfügen...</label>
</div>
 
<button type="submit" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored">
SPEICHERN
</button>
</form>
 
<ul class="demo-list-control mdl-list" id="todolist">
 
</ul>
 
</div>
</main>
</div>
</body>
 
</html>
"
I wanted to create an Todolist and it was compiled too, and there is a note too, but then the page gets reloaded for some reason. Do you know why? Should I just start from scratch?
HungaryBernd2023-12-08 19:38:19 · 3yNo. 295742reply
So basically you want a form where you add items to your to do list and a table (of one column) which displays the items?
I dunno why the above code don't work. What I'd do:
The form would be in input text field, and a button.
In js I would create an p element, which I would clone and append to the table container every time I click the button, it would get it's textcontent from the input field.
The button would get an eventlistener with the function doing this appending.
The "table" can be above ofc, and the "form" below (neither needs to be form and table html elements ofc).
The structure of the html would be:
- body < main < div1 (table) + div2 (form).
- div1 < h4 (To Do List) + p + p + p + p... (these generated by js)
- div2 < input (text) + button
Make the main flex, and center the content both vertically and horizontally. Make the divs fixed width. Add margins padding and whatnot to your liking.
Leave out the 3rd party crap (fonts and js).
HungaryBernd2023-12-08 19:45:37 · 3yNo. 295745reply
Also the function which adds the items to the table would also clear the input value so don't have to do it manually.
HungaryBernd2023-12-08 20:18:11 · 3yNo. 295749reply
Actually you need a container for the 'p' elements, to make it easy to add a "clear list" button , which would clear this container from elements.
And now I have more ideas like numbering the items, plus adding buttons for each to delete em individually.
Rabbit hole.
/tech/Post a Replyarrow_backarrow_upward