Javascript表单验证器没有提交

Javascript表单验证器没有提交

本文介绍了Javascript表单验证器没有提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在使用gen_validatorv4表单验证方法来验证表单值。但是,我在Javascript中制作了一个小型计算器,我不提交表单,按下按钮,计算出的值显示在提交表单的框中。



问题是,这个表单验证器显然只在onsubmit事件被触发时才会生效。有没有办法让表格得到验证而不会在提交的情况下进行验证?



请帮助!



谢谢: )

Hello,

I''m using the "gen_validatorv4" form validiation method to validiate form values. However, I''m making a tiny calculator in Javascript, in which I don''t submit form, I press on a button and the calculated values appear in a box whtout the form being submitted.

The problem is, that this form validiator apparently only comes into action when the onsubmit event is trigerred. Is there a way to get the form validiated without trigerring onsubmit?

Please help!

Thanks :)

推荐答案

<head>
    <script type="text/javascript">
        function validateData() {
            try {
                var data1 = document.getElementById("txt1").value;
                if (data1 == "submit") {
                    document.getElementById("Form1").submit();
                }
                else {
                    document.getElementById("div1").innerHTML = "You have said " + data1;
                }
            }
            catch (err) {
                document.getElementById("div1").innerHTML = err.Message;
            }
        }
    </script>
</head>
<body>
    <form id="Form1">
        If you want to submit, type the word: submit <br />
        <input id="Text1" name="txt1" type="text" />
        <div id="div2"></div>
        <input type="button"  önclick="javascript:validateData();" value="Validate Text" />";
    </form>
</body>


<!DOCTYPE html>
<html>
	<head>
		<title>Simple Calculator</title>
		<style type="text/css">
			#cntr {
				border: 1px solid black;
				display: inline-block;
				position: absolute;
				font-size: 50px;
			}
			button {
				width: 2em;
				font-size: 50px;
			}
		</style>
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
		<script type="text/javascript">
			var d;
			var val1 = 0;
			var val = 0;
			var op = '';



这篇关于Javascript表单验证器没有提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 22:28