AdBlock Detected

We provide high-quality source code for free. Please consider disabling your AdBlocker to support our work.

Buy me a Coffee

Saved Tutorials

No saved posts yet.

Press Enter to see all results

Remove Word From A Paragraph [Using JavaScript]

By pushpam abhishek
Listen to this article
Remove Word From A Paragraph [Using JavaScript]

Introduction


Here we will learn Remove Word From A Paragraph [Using JavaScript]This code will display a day in a week when the user submits the form input. The code use onclick() to call a function that will  Remove Word. This a free program feel free to modify it and use it in your systemThe code use onclick() function to call a specific function that dynamically Removes Word From A Paragraph. Feel free to modify and apply it in your system, this is a user-friendly kind of program We will be using JavaScript as a server-side scripting language because It gives greater control of your web page and extends its capability in a modern way approach. It is written in HTML or as external sourcing to add some necessary features to your website.

Getting started:

First, you have to download the bootstrap framework, this is the link for the bootstrap that I used for the layout design https://getbootstrap.com/.


How do I Remove Word From A Paragraph [Using JavaScript]

Description:

This code contains the interface of the application. To create this just write these blocks of code inside the text editor and save it as index.html.
To do this just copy and write these blocks of codes as shown below inside the text editor then save it as script.js inside the js folder.

<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1" /> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/> </head><body style="background-color:red"> <nav class="navbar navbar-default"> <div class="container-fluid"> <a class="navbar-brand" href="https://www.trickcode.in/">trickcode.in</a> </div> </nav> <div class="col-md-3"></div> <div class="col-md-6 well"> <h3 class="text-primary">Remove Word From A Paragraph Using JavaScript</h3> <hr style="border-top:1px dotted #ccc;"/> <div class="col-md-4"> <form> <div class="form-group"> <label>Enter a word</label> <input type="text" id="content"/> </div> <center><button type="button" id="remove" class="btn btn-primary">Remove</button></center> </form> </div> <div class="col-md-8"> <p id="result"></p> </div> </div></body><script src="js/script.js"></script>
</html>


Scricpts:
var paragraph = "Shattered soul, tattered mind. The way back is what I hope to find. Broken dreams lost without a trace. Lately I've been feeling a little out of place.";
document.getElementById('result').innerHTML = paragraph;
document.getElementById('remove').onclick = removeWord;
var newPa = "";

function removeWord(){
var content = document.getElementById('content');
var target = content.value;
if(content.value == ""){
alert("Please enter something first!");
}else{
if(newPa == ""){
newPa = paragraph.replace(new RegExp(target, 'g'), "");
}else{
newPa = newPa.replace(new RegExp(target, 'g'), "");
}
document.getElementById('result').innerHTML = newPa;
content.value = "";
}
}

Share this post

pushpam abhishek

About pushpam abhishek

Pushpam Abhishek is a Software & web developer and designer who specializes in back-end as well as front-end development. If you'd like to connect with him, follow him on Twitter as @pushpambhshk

Comments