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 url is like 'bugged', but if i use POST in method (form) I get the correct url but say this.
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.