Y
yuelinniao
hi, I have got a simple way to make "textarea" support "auto-submit"
when pressing Ctrl+Enter, and tested under both IE and Firefox.
The common old method is like this:
<form name=form2>
<textarea onkeydown='if(event.keyCode==13 && event.ctrlKey) return
document.form2.submit()'>
</textarea>
</form>
It is not good, because:
1) must give the FORM a name or id.
2) when the "name" of FORM changed, must change the code
3) worst is I must input(or copy) the code.....
I tried a simple way to do this boring thing, and only need input code
once.
1) write a js file, e.g. common.js
/*
* auto support Ctrl+Enter to submit form
* by Net@lilybbs (yuelinniao@hotmail)
*/
window.onload = function()
{
for(var i=0; i < document.forms.length; i++)
{
var frm = document.forms;
for(var j=0; j < frm.length; j++)
{
var e = frm.elements[j];
if(!e.type)
continue;
if(e.type=="textarea")
e.onkeydown = function(evt)
{
evt=(evt)?evt(event)?event:null);
if(evt.ctrlKey && evt.keyCode==13)
{
this.form.submit();
return false;
}
}
}
}
}
2) when import, the page's textarea(s) support Ctrl+Enter to submit
form
<script type="text/javascript" src="common.js"></script>
hope help someone. Sorry for my poor English.
when pressing Ctrl+Enter, and tested under both IE and Firefox.
The common old method is like this:
<form name=form2>
<textarea onkeydown='if(event.keyCode==13 && event.ctrlKey) return
document.form2.submit()'>
</textarea>
</form>
It is not good, because:
1) must give the FORM a name or id.
2) when the "name" of FORM changed, must change the code
3) worst is I must input(or copy) the code.....
I tried a simple way to do this boring thing, and only need input code
once.
1) write a js file, e.g. common.js
/*
* auto support Ctrl+Enter to submit form
* by Net@lilybbs (yuelinniao@hotmail)
*/
window.onload = function()
{
for(var i=0; i < document.forms.length; i++)
{
var frm = document.forms;
for(var j=0; j < frm.length; j++)
{
var e = frm.elements[j];
if(!e.type)
continue;
if(e.type=="textarea")
e.onkeydown = function(evt)
{
evt=(evt)?evt(event)?event:null);
if(evt.ctrlKey && evt.keyCode==13)
{
this.form.submit();
return false;
}
}
}
}
}
2) when import, the page's textarea(s) support Ctrl+Enter to submit
form
<script type="text/javascript" src="common.js"></script>
hope help someone. Sorry for my poor English.