admin管理员组

文章数量:1332339

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.

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.

Share Improve this question edited Aug 4, 2019 at 4:08 CommunityBot 11 silver badge asked Mar 1, 2012 at 22:44 DigitalJedi805DigitalJedi805 1,4604 gold badges16 silver badges42 bronze badges 2
  • Are you getting any errors or warnings in your javascript console? If so, could you post them here? – octern Commented Mar 2, 2012 at 0:48
  • 1 No, I'm octern. That's why "- octern" shows up at the end of my ments. – octern Commented Mar 2, 2012 at 16:59
Add a ment  | 

4 Answers 4

Reset to default 2

Your HTML could be like this:

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

Now use jQuery:

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

This is my jsFiddle: http://jsfiddle/mtwLf/1/

Try this:

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

the onChange function only works if you remove focus by clicking somewhere else

Try to use onBlur event instead onChange

I'd really start by breaking out that javascript into a separate file and doing it on/after document ready. I think ive seen people say that its a bad thing nowadays to write inline javascript.

Anyone have any thoughts on that?

本文标签: phpSubmit Text Type Field OnChangeStack Overflow