0

I have a button that directs to another website, and a submit input for my form.

When I click the submit button, it calls the function from the other button.

The submit should call validateForm(), but it calls validateRedirect() from the other button as you can see here:

<input type="submit" value="Submit Form" onclick="validateForm()"></input>

<button type="button" onclick="" >Help</button>
<br /><br />
<button type="button" onclick="validateRedirect()" >Go To Another Website</button> 

<script src="../js/myscript.js">

I can't figure out why it is doing it, does anyone know how to solve this?

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
Louiee
  • 75
  • 7
  • 2
    I think this might be a "bubbling" issue. In your validateForm() function try adding "event.preventDefault()" – adam.k Mar 25 '20 at 05:58
  • Thankyou, it worked. – Louiee Mar 25 '20 at 06:02
  • Glad it worked. If it is indeed in fact a bubbling issue and you are still having problems you should try event.stopPropagation() (not preventDefault, sorry for the confusion). This is a good explanation between the two https://stackoverflow.com/questions/5963669/whats-the-difference-between-event-stoppropagation-and-event-preventdefault – adam.k Mar 25 '20 at 06:09
  • 1
    i guess the problem here is that no matter what function you call you will always get redirected because you set that button to `type="submit"`. You think `validateForm()` redirects you but actually you get redirected by the default behaviour of forms – bill.gates Mar 25 '20 at 06:17

0 Answers0