-1

I'm trying to take an entry from a form then send this entery via a webhook link.

<form onsubmit="redirect()">
     <input type="text" id="firstName" name="First name" required />
     <button id="button">click</button>
   </form>

then

<script>
      finFirst = document.getElementById('firstName').value
      function redirect() {
      location.href = `https://myblahblahhook.com/webhook-test/my-form?first=${finFirst}`;
      }
    </script>

If I enter Mark as a username I will get the following:

http://127.0.0.1:5555/mysql-test/index.html?username=Mark

instead of

https://myblahblahhook.com/webhook-test/my-form?first=Mark

I apprecaite your help!! Thanks

Baraa

Baraa A
  • 1
  • 1
  • The form's default action is to submit to its action page (default is the same page); you have not prevented that from happening. You'll want to pass the submit event to your `redirect` function and then include `e.preventDefault()`. – mykaf Nov 30 '22 at 15:56
  • 1
    Why don't you use the `action` attribute of the `form`, to define the url the data should be sent to? And having `finFirst = document.getElementById('firstName').value` outside the `redirect` will read the value of `firstName` at the time the script is executed and not when the form is send. – t.niese Dec 01 '22 at 08:03
  • @t.niese Thank you. I appreciate it. That fixed the issue. I started JavaScript a week ago so it is little challenging right know. – Baraa A Dec 01 '22 at 13:51

1 Answers1

0

You mean this?

<form action="https://myblahblahhook.com/webhook-test/my-form">
    <input type="text" id="firstName" name="first" placeholder="First Name" required />
    <button id="button">click</button>