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

78
Views
send div content using form?

I vould like to send the div content in a form. But do not works! Can you please help me to find the missing part? The information sent in the db table is missing "empty space".

HTML

<form class="myform" action="file.php" method="POST">

   <div  id="mydiv">

        <p>Marco</p>

   </div>
   <input  type="hidden" name="dataInput" id="myinput">
   <button class="mybutton" type="submit">send</button>
</form>

JAVASCRIPT

let myForm = document.querySelector(".myform");

myForm.addEventListener("submit", function(x){
    
   x.preventDefault();
   let myInput = document.getElementById("myinput");
   let myDiv = document.getElementById("mydiv");
   
   myInput.value  =  myDiv.innerHTML;

   myForm.submit();
});

PHP file.php

  $info= $_POST['dataInput'];

  $data="INSERT INTO friends (
         friend) VALUES(
         '$info');";
  $results = mysqli_query($conn, $data);
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!