Skip to content

GitHub Pages URL parameters #22667

Discussion options

You must be logged in to vote

Hello @Galaxy-Coding, it depends on the form.

With HTML you can do:

<form>
  <input type="text" name="color" value="red"><br>
  <input type="submit" value="Submit">
</form> 

If sending to a new page, you can add the action attribute to <form>. (e.g. action=“my_url”)

or with JavaScript:

<form id="myForm">
  <input type="text" name="color" value="red"><br>
  <input type="submit" value="Submit">
</form> 
<script>
document.getElementById('myForm').onsubmit = function () {
  // set params using form values
  window.location.search = this.color.name + '=' + this.color.value;

// prevents normal form submission
return false;
};
</script>

If you’re setting the whole URL, you can use location.href

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants