更改时提交文本类型字段


Submit Text Type Field OnChange

我试图在更改HTML中的文本字段时提交一个表单。目前,我的代码看起来像这样:

echo("<form name='"editAgendaItem" . $this->Id . "'" id='"editAgendaItem" . $this->Id . "'" method='"post'" action='"./?module=meetings&preload=edit&function=editAgendaItem&agendaitem=" . $this->Id . "'">'n");
echo("<table width='"100%'" border=0>'n");
echo("<tr><td width='"20px'">" . $this->Index . "</td><td><input type='"text'" value='"" . $this->Title . "'" name='"agendaItemTitle" . $this->Id . "'" onChange='"javascript:document.forms['editAgendaItem" . $this->Id . "'].submit();'" />");
echo("</td>'n");
...

哪个评估为

<form name="editAgendaItem19" id="editAgendaItem19" method="post" action="./?module=meetings&preload=edit&function=editAgendaItem&agendaitem=19">
<table width="100%" border=0>
<tr><td width="20px">1</td><td><input type="text" value="" name="agendaItemTitle19" onChange="javascript:document.forms['editAgendaItem19'].submit()" /></td>
...

但更重要的是

<form name="editAgendaItem19" id="editAgendaItem19" method="post" action="...">
<input type="text" value="" name="agendaItemTitle19" onChange="javascript:document.forms['editAgendaItem19'].submit()" />
...
  • 它最终被一个标签终止。我的问题是,在修改字段并放弃焦点时,表单不会提交

提前感谢您的帮助。

编辑:

我还尝试在onChange事件中使用此方法,而不是内联代码:

<script type="text/javascript">
function submitForm(FormName)
{
  document.forms[FormName].submit();
}
</script>

编辑:

采纳了使用以下代码的建议:

<script>
$(document).ready(function(){
   $('#agendaItemTitle24').live('blur',function()
      $('#editAgendaItem24').submit();
   });
});​
</script>

在我的脑海里,和

<form name="editAgendaItem24" id="editAgendaItem24" method="post" action="...">
<input type="text" value="" name="agendaItemTitle24" id="agendaItemTitle24" />
</form>

在我的内容中。仍然没有骰子。

您的HTML可能是这样的:

<form name="myForm" id="myForm" method="post" action="...">
<input type="text" value="" name="myInput" id="myInput"/>  

现在使用jQuery:

<script type="text/javascript">
$(document).ready(function(){
   $('#myInput').live('blur',function(){
      $('#myForm').submit();
   });
});​
</script>

这是我的jsFiddle:http://jsfiddle.net/mtwLf/1/

试试这个:

onkeyup="javascript:document.forms['editAgendaItem19'].submit()"

onChange函数只有在通过单击其他位置来移除焦点时才有效。

尝试使用onBlur事件而不是onChange

我真的会从将javascript分解成一个单独的文件开始,并在文档准备好后进行。我想我看到有人说现在写内联javascript是件坏事。

有人对此有什么想法吗?