Humanity Expired Humanity Expired - 1 month ago 5
HTML Question

Html send userinput to td

I input a text from the textfield and the text that i input is appearing in TD and then its always gone

first_name is the userinput

f1 is the td

function ajax_post(){
var fn = document.getElementById("first_name").value;


var table = $("#f1");
table.text(fn);


}


my submit button

<input name="myBtn" type="submit" value="Submit Data" onClick="ajax_post();">


i'm using
<form> </form>


i'm wondering that my script is kinda wrong

Answer

function ajax_post(){
  var fn = document.getElementById("first_name").value;
  var table = document.getElementById("f1");
  table.innerText = fn;
 }
<!DOCTYPE html>
<html>

  <head>
    <link rel="stylesheet" href="style.css">
    <script src="script.js"></script>
  </head>

  <body>
    <form onsubmit="return false;">
      <input type="text" id="first_name" />
      <input name="myBtn" type="submit" value="Submit Data" onClick="ajax_post();">
    </form>
    
    <table>
      <tr>
        <td id="f1"></td>
      </tr>
    </table>
  </body>

</html>