Humanity Expired Humanity Expired - 10 months ago 65
HTML Question

Html Textinput in Table Data

Our teacher want us to create a website that will recieve text from the user (textfield) and send it to table data and it need to be in


When i use
i input text in textfield the text and submit it the text that i enter is showing in table data at the same time its gone like in the text field i know that this is because of
when i remove the
the text is showing in table data.

Here is my code :

Name: <input action="f1.document.getElementById("first_name");" id="first_name" size="30" type="text" >

<button class="okok" name="myBtn" type="submit" value="Submit Data" onClick="ajax_post();">COMPUTE </button>


<td style="color:white;" id=f1 > </td>

in script

function ajax_post(){

var fn = document.getElementById("first_name").value;
var table = document.getElementById("f1");
table.innerText = fn;

Answer Source

That's because the button is 'submitting' the form, which is like refreshing to page in that it will clear the values.

You have to stop the form submitting, like this:

<form onsubmit="return false;">