Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
JavaScript send data from input field to ajax request

I have following Code. But the String in the Database is empty. Why does it not work to get the string from the input field?

HTML

 <div id="todo">
   <h2>Todo Liste</h2> 
   <form method="get">
     <input type="text" name="username" placeholder="name" required>
     <input type="text"  class="inputField" name="inputData" id="myInput" placeholder="title"  required><br><br>
     <span onclick="newElement(); sendData(this.value)" class="addBtn">Add</span><br><br>
    </form>

JavaScript

function sendData(str) {
  const xmlhttp = new XMLHttpRequest();
  xmlhttp.onload = function() {
    document.getElementById("txtHint").innerHTML = this.responseText;
  }
  xmlhttp.open("GET", "saveData.php?q=" + str);
  xmlhttp.send();
}

To get the Value on the html page:

<p>Response from PHP <span id="txtHint"></span></p> 

to bring the data in the html

function newElement() {
var li = document.createElement("li");
var inputValue = document.getElementById("myInput").value;
var t = document.createTextNode(inputValue);
    li.appendChild(t);
  
      document.getElementById("myUL").appendChild(li);
    
  }

and i want to get the data of the text, a user typed in. this is where i fail.

My idea was

console.log(document.getElementsByClassName("inputField"));

How can I get the element?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!