带有提交按钮的多个JS

Multiple JS with submit button

我创建了一个表单,该表单正在提交整个表单并阻止页面在本地重新加载。

一旦发布到网站,我们就会尝试插入处理程序 (SalesForce)。表单仍会提交,但页面会重新加载,我们无法做到这一点。因为一旦单击 "submit" 按钮就会显示数据。该按钮正在控制多个JS和功能。

谁能看看代码,看看问题出在哪里?

<div>
<div class="columns medium-6">

<script type="text/javascript">
                function randomnumber() {
                    document.forms[0].Code.value=(Math.round(Math.random()*999999+1)); }
                onload=randomnumber
            </script>

            <div class="form-group">
                <label for="firstname">First Name</label>
                <input type="text" class="form-control" name="first_name" id="firstname" aria-describedby="firstname" placeholder="First Name">

                <label for="lastname">Last Name</label>
                <input type="text" class="form-control" name="last_name" id="lastname" aria-describedby="lastname" placeholder="Last Name">

                <label for="email">Email address</label>
                <input type="text" class="form-control" name="email" id="email" aria-describedby="email" placeholder="Email">

                <label for="phone">Phone</label>
                <input type="text" class="form-control" name="phone" id="phone" aria-describedby="phone" placeholder="Phone">

                <!--<input type="hidden" name="Owner" value="00G1a000001I7EA"> -->
                <input type="hidden" name="form_type" value="CSF">
                <input type="hidden" name="visitor_type" value="NEW-CUST">
                <input type="hidden" name="party_size" value="1">
                <input type="hidden" name="source" value="Love Happens Here">
                <input type="hidden" name="webtoleadstoreid" value="a0C1a00000BJhea">
                <input type="hidden" name="company" value="New Guest">
                <input type="hidden" name="reason_visit" value="other">

            <button type="submit" id="randomNumber" onclick="javascript:toggle(); return false;" class="btn btn-primary" value="Generate Code">Submit</button>

                <script language="javascript"> 
                    function toggle() {
                        var ele = document.getElementById("toggleText");
                        var text = document.getElementById("randomNumber");
                        if(ele.style.display == "block") {
                            ele.style.display = "none";
                            text.innerHTML = "show";
                        }
                        else {
                            ele.style.display = "block";
                            text.innerHTML = "Submit";
                        }
                    }

                    function showdiv()  {
                        var error = false;
                            //validate your form.
                        if(error == true){ return true;}
                        else
                        {
                            //show div
                            return false;
                        }
                    }
                </script>

                <div id="toggleText" style="display: none">
                <label for="code">Code</label>
                <input type="text" name="Code" readonly id="Code" aria-describedby="code" placeholder="code">
                <p> Check your email for the coupon code and details. Thanks again for your participation in our Share & Win contest, winners will be announced on <strong>February 14th.</strong></p>
                </div>

            </div>    
        </form>
    </div>
</div>

正如我所说,您可以使用 Ajax 来实现您想要的。 这里有一些链接可以帮助您朝这个方向发展

Ajax

Ajax

如果它们不能真正帮助您,请尝试使用谷歌搜索 Ajax,您一定会找到一个向您解释一切的网站。