In: Computer Science
Once the form in this file is submitted, create a new paragraph that will stack on top of the existing paragraphs and will contain the data entered into the textarea. Each new paragraph should have the class 'tweet' applied to it.
*Hint: Remember to use return false; to stop the form submission from reloading the page.
<!DOCTYPE html>
<html>
<head>
<title>Simple Twitter</title>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
crossorigin="anonymous">
<style>
.tweet{border-top:1px solid #dedede;
padding:20px;}
</style>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body class="container" style="width:50%">
<h1>Twitter</h1>
<form id="tweetForm" action="" method="">
<div
class="form-group">
<textarea
class="form-control tweetText" rows="3"></textarea>
</div>
<div class="form-group
float-right">
<input
type="submit" class="tweetBtn btn btn-primary"
value="Tweet">
</div>
</form>
<div
style="clear:both;"> </div>
<p class="tweet">I'm having lunch right
now</p>
<p class="tweet">This is my first
Tweet!!</p>
</body>
</html>
It should maybe be something structure like this, not sure.
$('#eventExample').submit(function(){
$(this).find('input').attr('disabled', true); //find() gets an
elements descendants
return false;
});
Deserves thumbs up :)
<!DOCTYPE html>
<html>
<head>
<title>Simple Twitter</title>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
crossorigin="anonymous">
<style>
.tweet{border-top:1px solid #dedede; padding:20px;}
</style>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body class="container" style="width:50%">
<h1>Twitter</h1>
<form id="tweetForm" action="" method="">
<div class="form-group">
<textarea id="myInput" class="form-control tweetText"
rows="3"></textarea>
</div>
<div class="form-group float-right">
<input onclick="newElement()" class="tweetBtn btn btn-primary"
value="Tweet">
</div>
</form>
<div style="clear:both;"> </div>
<div id="myUL">
<p class="tweet">I'm having lunch right now</p>
<p class="tweet">This is my first Tweet!!</p>
</div>
<script>
function newElement() {
var li = document.createElement("p");
li.setAttribute("class", "tweet");
var inputValue = document.getElementById("myInput").value;
var t = document.createTextNode(inputValue);
li.appendChild(t);
if (inputValue === '') {
alert("You must write something!");
} else {
document.getElementById("myUL").appendChild(li);
}
}
</script>
</body>
</html>