多个JS提交按钮

时间:2017-01-20 19:11:21

标签: javascript html forms salesforce form-submit

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

一旦发布到网站,我们就会尝试插入处理程序(SalesForce)。表单仍然提交,但页面重新加载,我们不能这样。由于有数据显示一旦"提交"单击按钮。该按钮控制多个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>

1 个答案:

答案 0 :(得分:0)

就像我说的,你可以使用Ajax来实现你想要的。 以下是一些可以帮助您实现这一目标的链接

Ajax

Ajax

如果他们真的没有帮助你,尝试使用谷歌搜索Ajax,你一定会找到一个网站,向你解释一切。