I’m trying to submit a form upon changing of a text field in HTML. Currently, my code looks something like this:
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");
...
Which evaluates to
<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>
...
But more importantly
<form name="editAgendaItem19" id="editAgendaItem19" method="post" action="...">
<input type="text" value="" name="agendaItemTitle19" onChange="javascript:document.forms['editAgendaItem19'].submit()" />
...
- Which is eventually terminated by a tag. My problem is that upon modifying the field and dropping focus, the form does not submit.
Thanks in advance for any help.
Edit:
I’ve also tried using this method in the onChange event instead of in-line code:
<script type="text/javascript">
function submitForm(FormName)
{
document.forms[FormName].submit();
}
</script>
Edit:
Took the suggestion to use the following code:
<script>
$(document).ready(function(){
$('#agendaItemTitle24').live('blur',function()
$('#editAgendaItem24').submit();
});
});
</script>
In my head, and
<form name="editAgendaItem24" id="editAgendaItem24" method="post" action="...">
<input type="text" value="" name="agendaItemTitle24" id="agendaItemTitle24" />
</form>
In my content. Still no dice.
Your HTML could be like this:
Now use jQuery:
This is my jsFiddle: http://jsfiddle.net/mtwLf/1/