Stonydallas Stonydallas - 1 year ago 57
HTML Question

Beginner alert. I need to get information from a webpage that's submitted by a user

I am making a find and replace algorithm for my website.
The aim is to let the user enter his/her text and it be run through an algorithm that changes certain words. The topics that I am trying to address here are

  1. How to get the text from the user.

  2. How to run it through the algorithm.

  3. How to make the algorithm.

I would like to use HTML or JavaScript, but will go with any thing that gets the job done.

Answer Source

Here is a simple program that has things that can be improved but I hope it'll help you get started:

<!DOCTYPE html>
<script src="jquery.js"></script>
function replaceText(){
    // witth is not a spelling error, you cant
    // use with for a variable name
    // create array of replace objects
    var rep =[
        {replace : "cat", witth : "hat"}, 
        {replace : "dark", witth : "light"}
    ], // declare the rest of the variables
    // get value of the textarea
    // return text is now the value of the textarea
    // for every object in the rep (replace) array
        // replace "replace" with "witth" using
        // rep array
        returnText=returnText.replace(new RegExp(
    // set value of the text area
<body >
<textarea id="txt">The dark cat.</textarea>
<input type="button" onclick="replaceText();" value="Replace"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download