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

94
Views
submit form along with request parameter

i want to use javascript to submit my form to the backend. However, I have to add a variable parameter to the form url/action endpoint as well. Wondering what the javascript way of doing this is?

This is what i have now

<form id="profile-message-form" action="/send-message?to" method="get">
   <textarea name="message-content" id="message-content" maxlength="1000" contentEditable="true"></textarea>
   <div id="send-button-container">
       <button id="profile-message-submit" onclick="sendMessage('profile-message-form')" name="subject" type="submit"><i id="profile-message-send-icon" class="fas fa-paper-plane"></i><p>Send</p></button>
   </div>
</form>

function sendMessage(form_id) {
    var form = document.getElementById(form_id);
    // find email address to send to
    // submit form with email address as ":to" req param
    form.submit();
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The easiest way is to add hidden fields to form before submitting it.

const formEl = document.getElementById('form');

formEl.onsubmit = e => {
  e.preventDefault();
  
  const hiddenAgeEl = document.createElement('input');
  hiddenAgeEl.type = 'hidden';
  hiddenAgeEl.name = 'age';
  hiddenAgeEl.value = 22;
  
  formEl.append(hiddenAgeEl);
  
  formEl.submit();
}
<form id="form" action="/send-message?to" method="get">
   <input type="text" name="name">
   <button type="submit">Submit</button>
</form>

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!