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

116
Views
echoing the text message from textarea via PHP and AJAX jQuery

HTML:

   <div class="mb-3">
       <label for="comment" class="form-label">Comments</label>
       <textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
   </div>

javascript:

let comment = $('textarea.msg').val()
alert(comment);

and then PHP:

echo $_POST['comment'];
echo isset($_POST['comment']);
echo trim($_POST['comment']) != '';

Here, the Response tab in Network tab of Firefox Inspect shows nothing for the echo commands in PHP. I am not sure why the textarea input hi is not shown hence not inserted.

Even for the javascript alert of comment variable, I get this:

enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

 let comment = $('#comment').val().trim();

Credits to Chris Haas.

about 4 years ago · Juan Pablo Isaza Report

0

<div class="mb-3">
   <label for="comment" class="form-label">Comments</label>
   <textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
</div>

id is unique in the HTML and with jquery it would be easier to target the element you want. For class we use $(.<classNAME>) while for id we use $(#<id_Name>)

Your Case, $('#comment').val()

about 4 years ago · Juan Pablo Isaza Report
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!