0

I have used this function to fetch some data with help of XMLHttpRequest()

function fetchTab1(id) {
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("table_data_1").innerHTML = this.responseText;
        }
    };
    
    xhttp.open("GET", "visit_fetch1.php?id=" + id, true);
    xhttp.send();
}

var id = document.getElementById('member_uniq_id').value;
fetchTab1(id);

If the html data I am getting from response text contains a html form, can I submit it?

Błażej Michalik
  • 3,174
  • 27
  • 41
  • 3
    Sure, why wouldn't you? Have you tried? – Scott Marcus May 05 '20 at 22:29
  • Here is a question that asks about how to submit a form via JavaScript: https://stackoverflow.com/q/1960240/783510 Does it help you? It uses jQuery though. Not sure if that is a problem in your environment. – Philipp Claßen May 05 '20 at 22:32
  • You can for instance do `document.querySelector('table_data_1 form').submit()` after inserting the reply, I'm wondering what the point is though? Submitting a form that was fetched from the server is 100% redundant. – Chris G May 05 '20 at 22:35
  • @PhilippClaßen No that's not my case, my form is generated using ajax! – psimanta May 05 '20 at 22:39
  • I tried, but the submit button doesn't do anything, if I directly put the form code in the main page, it is working! – psimanta May 05 '20 at 22:41
  • @ChrisG Actually I have a pretty big code, I use bootstrap tabs, Now I just want to apply ajax, to split them – psimanta May 05 '20 at 22:43
  • https://jsfiddle.net/sv18a4ct/ Just from a quick test, the form has to be in the DOM for the submit to work. You can't just have it in a DOM Fragment. – Taplar May 05 '20 at 22:46
  • Sorry but I don't understand how the fact that you're using bootstrap tabs relates to your question or my comment. Submitting a form will a) send data to the server then b) navigate to the reply. This is almost guaranteed to be an [xy problem](http://xyproblem.info) – Chris G May 05 '20 at 22:47

1 Answers1

0

So I came to find out that when I use td (Because put the form fields in columns of a table) I tag inside a form it is not working, but when I removed them, it started to work.