0

I'm trying to redirect the user to another page, but, it need to be after the form submit, but I don't know how should I do it. I'm using php to submit the form, everything works, less this part, if needed I can post the PHP forms here. I don't want to redirect in php because I would have to create a section/take its data to get the option that have been choose.

On this code, after the selection of an option, the user is automaticaly redirected to the page linked to the option, not submiting the form.

This is what I have.

<form>
  <select data-select-name="" id="select-45ba" name="select" class="u-border-1 u-border-grey-30 u-input u-input-rectangle u-radius-50 u-white u-input-15">
    <option value="QTD">QTD</option>
    <option value="index.html">1 - R$32</option>
    <option value="https://linkedin.com">2 - R$64</option>
    <option value="https://twitter.com">3 - R$96</option>
    <option value="https://instagram.com">4 - R$128</option>
    <option value="https://youtube.com">5 - R$160</option>
  </select>
  
  <script type="text/javascript">
    document.addEventListener('DOMContentLoaded', function() {
      document.querySelector('select[data-select-name]').onchange = changeEventHandler;
    }, false);

    function changeEventHandler(event) {
      window.location.submit = this.options[this.selectedIndex].value;
    }
  </script>
  
  <button type="submit">Submit</button>
</form>
biberman
  • 5,606
  • 4
  • 11
  • 35
Antoniazi
  • 23
  • 2
  • Use PHP to do the redirect instead, once it's processed the form data as needed. – ADyson Nov 07 '22 at 22:12
  • Thanks for the update. Are you saying you want this to be entirely client-side? Well if you want to wait until the form is submitted, handle the form's JS "submit" event instead of handling the "change" event of the select. – ADyson Nov 07 '22 at 22:21
  • See https://stackoverflow.com/questions/5384712/intercept-a-form-submit-in-javascript-and-prevent-normal-submission – ADyson Nov 07 '22 at 22:22

0 Answers0