0

this is a simple program where the first input set the text and the second and third inputs searchfor a word and replace it with another, I have fixed any errors brought to my attention by the console but with no errors immediately present it still does not work.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>string</title>
    <link rel="stylesheet" href="styles.css">
    <meta name="author" content="Dylan Handy">
    <meta name="description" content="No purpose">
    <meta name="keywords" content="fill, in, your, keywords, here">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Rock Salt">
</head>
<body>
    <form>
<input id="inputbox" type="text" placeholder="Text goes here">
<button type="submit" onclick="plcr()">Submit</button>
<p  id="textbox"  style="background:rgb(160, 158, 158); height: 200px; width: 500px;" ></p>
<input id="search" type="text" placeholder="Search">
<input id="replace" type="text" placeholder="Replace">
<button type="submit" onclick="rplc()">Submit</button>
</form>
    <script>
function plcr(){
"use strict";
    var a = document.getElementById("inputbox").innerHTML;
    console.log('a');
    document.getElementById("textbox").innerHTML = a ;
    
    // b.innerHTML =a; 
    
    

}
function rplc(){
    var b = document.getElementById("textbox").innerHTML;
    var y = document.getElementById("textbox").innerHTML;
    var x = document.getElementById("search").innerHTML;
    
    if(y.contains(x)){
        b.replace(y,x);
    }
    
}
    </script>
</body>
</html>
  • Welcome to Stack Overflow! Please take the [tour] (you get a badge!), have a look around, and read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) I also recommend Jon Skeet's [Writing the Perfect Question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) and [Question Checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Whenever saying "it doesn't work," always be sure to say **in what way**. What do you see? What do you expect? What happens instead? – T.J. Crowder May 07 '21 at 15:39
  • To get the text of the `input`, use `value` not `innerHTML`. Also, if you don't want the `button` to submit the form, use `type="button"` on it. – T.J. Crowder May 07 '21 at 15:39
  • 1
    You're not using the result of `b.replace(y,x);` – Gerard van Helden May 07 '21 at 15:39
  • Good catch @GerardvanHelden - Dylan, details here: https://stackoverflow.com/questions/1433212/replace-method-doesnt-work – T.J. Crowder May 07 '21 at 15:40

0 Answers0