Submit HTML form, perform javascript function (alert then redirect)

后端 未结 3 895
感情败类
感情败类 2021-02-01 05:58

I have a JavaScript function that works great when I call it through an \'onClick\' method. Basically what it does is pull data from a html form, and then based on that data, re

相关标签:
3条回答
  • 2021-02-01 06:22
    <form action="javascript:completeAndRedirect();">
        <input type="text" id="Edit1" 
        style="width:280; height:50; font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif; font-size:22px">
    </form>
    

    Changing action to point at your function would solve the problem, in a different way.

    0 讨论(0)
  • 2021-02-01 06:22

    You need to prevent the default behaviour. You can either use e.preventDefault() or return false; In this case, the best thing is, you can use return false; here:

    <form onsubmit="completeAndRedirect(); return false;">
    
    0 讨论(0)
  • 2021-02-01 06:36

    Looks like your form is submitting which is the default behaviour, you can stop it with this:

    <form action="" method="post" onsubmit="completeAndRedirect();return false;">
    
    0 讨论(0)
提交回复
热议问题