How can I make a tag in IE7 submit the form, while doing all the form validation that is setup on the form?
我如何在IE7中做一个标签提交表单,同时在表单上做所有的表单验证?
if I just do a document.forms[0].submit();
it submits, but ignores form validation.
如果我只做document。forms[0]。submit();它提交,但忽略表单验证。
Edit: Everybody likes telling me to use the input tag... That will sumbit the form but wont work in my situation which is why i asked about the button tag...
编辑:每个人都喜欢告诉我使用输入标签…这将包含表单,但在我的情况下不起作用,这就是为什么我要问按钮标签……
<form action="my/script" onsubmit="return ValidateFunc();">
<button> <img src="image/do_this_with_input_tag.png"> Some Text </button>
</form>
6 个解决方案
#1
9
First have a button with type submit as
首先有一个按钮,类型为submit as
<input type="submit" value="submit" />
In your form tag, include the onsubmit() event as
在您的表单标记中,包括onsubmit()事件。
<form
action="/path/to/server/side/script"
name="testform"
onsubmit="return validate()"
>
The validate()
function should return true
if the form validation goes through or a false
if the validation fails. e.g.
如果表单验证通过,则validate()函数应该返回true;如果验证失败,则返回false。如。
function validate(){
if(...){//valid
return true;
}else{//not valid
return false;
}
}
EDIT: Always specify the button type. If not specified, in IE it defaults to "button" while in Chrome and Firefox it defaults to "submit".
编辑:始终指定按钮类型。如果没有指定,在IE中默认为“按钮”,在Chrome和Firefox中默认为“提交”。
<form action="my/script" onsubmit="return ValidateFunc();">
<button type="submit"> <img src="image/do_this_with_input_tag.png"> Some Text </button>
</form>
And in future, include more details in your question if you want proper answers.
在将来,如果你想要正确的答案,可以在你的问题中加入更多的细节。
#2
2
I solved this simply by adding type="submit"
to the button.
我通过向按钮添加type="submit"来解决这个问题。
<button>Submit</button>
was not submitting in IE7.
在IE7中未提交。
<button type="submit">Submit</button>
does submit in IE7.
在IE7中提交。
#3
1
I guess that the Validation only recognize a "submit" event from a "submit" button.
我猜验证只从“提交”按钮识别“提交”事件。
You should use a "submit" input instead of a "button" input. Then the validation mechanism will be able to intercept the submit event. you can call form.submit within the validation.submit function.
您应该使用“提交”输入而不是“按钮”输入。然后验证机制将能够拦截提交事件。你可以叫形式。内提交验证。提交功能。
Here's the code:
这是代码:
<form id="theForm">
...
<input type="submit" value="submitMe"/>
</form>
in Javascript:
在Javascript中:
$('#theForm').validate({
...
submitHandler: function() {
// do some trick here
...
// submit the form
$('#theForm').submit();
}
});
#4
1
I used jquery to submit the button. If i use straight javascript if bypasses the validation setup. Jquery 's form submit runs the validation before submitting.
我使用jquery提交按钮。如果我使用直接的javascript,如果绕过验证设置。在提交之前,Jquery的表单提交运行验证。
After additional research, the tag, even with a type="submit" cannot submit a form in older version of IE.
经过进一步的研究,标签,即使类型="submit"也不能提交旧版本IE的表单。
#5
0
I'm using (dummy/not visible) input field inside form positioned absolute with this css:
我正在使用(虚拟/不可见)输入字段,在表单中使用这个css:
<input class="dummy" type="submit" />
.dummy {
position:absolute;
bottom:0px;
right:0px;
padding:0px;
margin:0px;
border:0px;
font-size:0px;
line-height:0px;
}
Just avoid using display:none or visibility:hidden or width:0px etc. Use only this css i have provided.
避免使用显示:没有或可见:隐藏或宽度:0px等等。只使用我提供的这个css。
#6
0
I had the same problem with IE11 with a submit button inside another form:
我对IE11也有同样的问题,在另一个表单中有一个提交按钮:
<form id="form1">
...
</form>
<form id="form2">
...
<button type="submit" form="form1">OLA KE ASE</button>
...
</form>
You can solve it usign javascript, i did it with jQuery on a generic way.
你可以解决它usign javascript,我用jQuery做了一个通用的方法。
$(document).ready(function() {
$('button[type=submit]').on('click', function() {
if ($(this).attr('form') != '') {
document.getElementById($(this).attr('form')).submit();
}
});
});
#1
9
First have a button with type submit as
首先有一个按钮,类型为submit as
<input type="submit" value="submit" />
In your form tag, include the onsubmit() event as
在您的表单标记中,包括onsubmit()事件。
<form
action="/path/to/server/side/script"
name="testform"
onsubmit="return validate()"
>
The validate()
function should return true
if the form validation goes through or a false
if the validation fails. e.g.
如果表单验证通过,则validate()函数应该返回true;如果验证失败,则返回false。如。
function validate(){
if(...){//valid
return true;
}else{//not valid
return false;
}
}
EDIT: Always specify the button type. If not specified, in IE it defaults to "button" while in Chrome and Firefox it defaults to "submit".
编辑:始终指定按钮类型。如果没有指定,在IE中默认为“按钮”,在Chrome和Firefox中默认为“提交”。
<form action="my/script" onsubmit="return ValidateFunc();">
<button type="submit"> <img src="image/do_this_with_input_tag.png"> Some Text </button>
</form>
And in future, include more details in your question if you want proper answers.
在将来,如果你想要正确的答案,可以在你的问题中加入更多的细节。
#2
2
I solved this simply by adding type="submit"
to the button.
我通过向按钮添加type="submit"来解决这个问题。
<button>Submit</button>
was not submitting in IE7.
在IE7中未提交。
<button type="submit">Submit</button>
does submit in IE7.
在IE7中提交。
#3
1
I guess that the Validation only recognize a "submit" event from a "submit" button.
我猜验证只从“提交”按钮识别“提交”事件。
You should use a "submit" input instead of a "button" input. Then the validation mechanism will be able to intercept the submit event. you can call form.submit within the validation.submit function.
您应该使用“提交”输入而不是“按钮”输入。然后验证机制将能够拦截提交事件。你可以叫形式。内提交验证。提交功能。
Here's the code:
这是代码:
<form id="theForm">
...
<input type="submit" value="submitMe"/>
</form>
in Javascript:
在Javascript中:
$('#theForm').validate({
...
submitHandler: function() {
// do some trick here
...
// submit the form
$('#theForm').submit();
}
});
#4
1
I used jquery to submit the button. If i use straight javascript if bypasses the validation setup. Jquery 's form submit runs the validation before submitting.
我使用jquery提交按钮。如果我使用直接的javascript,如果绕过验证设置。在提交之前,Jquery的表单提交运行验证。
After additional research, the tag, even with a type="submit" cannot submit a form in older version of IE.
经过进一步的研究,标签,即使类型="submit"也不能提交旧版本IE的表单。
#5
0
I'm using (dummy/not visible) input field inside form positioned absolute with this css:
我正在使用(虚拟/不可见)输入字段,在表单中使用这个css:
<input class="dummy" type="submit" />
.dummy {
position:absolute;
bottom:0px;
right:0px;
padding:0px;
margin:0px;
border:0px;
font-size:0px;
line-height:0px;
}
Just avoid using display:none or visibility:hidden or width:0px etc. Use only this css i have provided.
避免使用显示:没有或可见:隐藏或宽度:0px等等。只使用我提供的这个css。
#6
0
I had the same problem with IE11 with a submit button inside another form:
我对IE11也有同样的问题,在另一个表单中有一个提交按钮:
<form id="form1">
...
</form>
<form id="form2">
...
<button type="submit" form="form1">OLA KE ASE</button>
...
</form>
You can solve it usign javascript, i did it with jQuery on a generic way.
你可以解决它usign javascript,我用jQuery做了一个通用的方法。
$(document).ready(function() {
$('button[type=submit]').on('click', function() {
if ($(this).attr('form') != '') {
document.getElementById($(this).attr('form')).submit();
}
});
});