mardi 20 juillet 2021

Conditional HTML form based on the beginning letter in a Text Field

I'm making an HTML form where the user submits a user ID, and based on the first letter of that ID, it will redirect to specific page of a website.

The website is a WordPress site, and every time I test it, instead of going to my placeholders links (Youtube & Reddit), it goes to a blank WP page based off the inputted ID.

Eg. Submitting "A123" directs to website.com/?participantID=A123 instead of Reddit (placeholder site).

This could be a WP issue, but feel like I'm not turning the input into a string correctly. Honestly, I'm not that confident with any of the JS I've written Any help is appreciated. Thanks!

<form onsubmit="pageRedirect()">
  
<input type="text" id="participantID" name="participantID">
<input type="submit">
</form>

<script>
  let inputValue = document.getElementById("participantID");

pageRedirect() {

if ("inputValue".startsWith("A")) {
action="https://reddit.com";
}
else {
    action="https://youtube.com";
  }
}
  </script>

Aucun commentaire:

Enregistrer un commentaire