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

152
Views
Set different url in the action(form) based on input

I want the action of the form to have different urls based on the input that is passed to it, the problem is that passing the correct urls to the action does not work as it should.

Next I will put some images to be more descriptive

This is the form

<div id="search">
    <form id="formID" action="javascript:;" onsubmit="chgAction()" autocomplete="off">
        <input id="inputID" type="text" placeholder="Search.." autofocus="autofocus">
    </form>
</div>

Here I take the value of the input and I nest it to reddit and in the end I pass it as action and it doesn't work

var text = document.getElementById("inputID").value
document.getElementById("formID").action = "https://www.reddit.com/search/?q=" + text;

The result is this enter image description here

The url is like 'bugged', but if i use POST in method (form) I get the correct url but say this.

enter image description here

But If i click on the url then enter if it works. enter image description here

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

0

I believe it is because the GET request is sending out the request before you can obtain the value of the input. I would suggest using e.preventDefault() instead, then create your URL based on the input, then send a fetch() request.

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!