添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
打篮球的口罩  ·  将 Visual Studio .NET ...·  3 月前    · 
听话的板栗  ·  i-net Clear Reports - ...·  4 月前    · 
读研的盒饭  ·  socket.recv - 邹雷·  4 月前    · 
稳重的佛珠  ·  未处理的异常: ...·  6 月前    · 

Has anyone had a simple select statement within a form with an Onchange=“this.form.submit();” not submit the form when the value is changed?

I have 2 other forms within the same page with Onchange=“this.form.submit();” that work.

I’ve tried specifically naming the form with an id and using getelementbyid to submit the form, modifying the form name and submitting it with that specific form name, creating a javascript function to submit the form and other options that will submit forms.

I’m pulling my hair out! It’s simple html code that should work 100% of the time.

Below is the piece of code that pertains to this form and select statement.

<table width="100%">
<form name="form" method="post"  action="">
<cfoutput>
  <input name="pafnumber" type="hidden" value="#form.pafnumber#">
  <input name="positionnumber" type="hidden" value="#form.positionnumber#">
  <input name="paftype" type="hidden" value="#form.paftype#">
  <cfif form.pafnumber neq "">
    <td width="50%" nowrap="nowrap"><div align="right"><strong>PAF Number:</strong></div></td>
    <td width="50%"nowrap="nowrap">#recordset1.pafnumber#</td>
  </cfif>
  <cfif form.pafnumber neq "">
    <td width="50%" nowrap="nowrap"><div align="right"><strong>EPAF Type:</strong></div></td>
    <td width="50%">#recordset1.pafdescription#</td>
  </cfif> 
  <td width="50%" nowrap="nowrap"><div align="right"><strong>Appointment Type:</strong></div></td>
  <td width="50%">
 <select name="appointmenttype" onchange="this.form.submit();">
  <option value="">Select Appointment Type</option>
  <cfoutput query="getappt">
  <option value="#getappt.appointmenttype#" <cfif getappt.appointmenttype eq "#recordset1.appointmenttype#"> selected </cfif>>#getappt.appointmentdescription#</option>
  </cfoutput>
  </select>
  <td width="50%" nowrap="nowrap"><div align="right"><strong>First Name:</strong></div></td>
  <td width="50%" nowrap="nowrap"><input name="firstname" type="text" value="#recordset1.firstname#" onselect="this.form.submit();" ></td>
  <td nowrap="nowrap"><div align="right"><strong>Last Name:</strong></div></td>
  <td><input name="lastname" type="text" value="#recordset1.lastname#"/></td>
</cfoutput> 
<cfoutput>
<td nowrap="nowrap"><div align="right"><strong>Effective Date:</strong></div></td>
<td><input name="dateofactionfrom" id="dateofactionfrom" type="text" value="#dateformat(recordset1.dateofactionfrom,'mm/dd/yyyy')#"/></td>
<cfif form.pafnumber neq "">
<cfif form.paftype eq 'LV' or form.appointmenttype eq 'TEMP'>
<td nowrap="nowrap"><div align="right"><strong>End Date:</strong></div></td>
<td><input name="dateofactionto" id="dateofactionto" type="text" value="#dateformat(recordset1.dateofactionto,'mm/dd/yyyy')#"/></td>
</cfif>
  <td valign="top">&nbsp;</td>
  <td valign="top">&nbsp;</td>
  <td valign="top"><div align="right"><strong>Comments:</strong></div></td>
  <td valign="top"><textarea name="comments" cols="50" rows="4">#tostring(Recordset1.comments)#</textarea></td>
</cfif>
  <td colspan="2">&nbsp;</td>
</cfoutput>
<td colspan="2">
<div align="center">
<cfif form.pafnumber eq "">
<input name="submit" type="submit"  value="Create PAF"/>
</cfif>
<cfif form.pafnumber neq "">
<input name="submit" type="submit"  value="Update"/>
</cfif>
  <td colspan="2">&nbsp;</td>
</form> 
</table>

Yes I’m getting a
Uncaught TypeError: Cannot read properties of null (reading ‘submit’)
at HTMLSelectElement.onchange

My select tag is a bit more complicated than the above example and is in a form…

With this you are referencing the dom node of the <select> tag, and that doesn’t have a form to submit. Instead, I’d add an ID to the form tag and reference it by the ID and submit it then. Something similar to:

<form id="myForm"...>
<select onchange="let el=document.getElementById('myForm);el.submit();">
</form>

But of course, it depends what you are trying to do exactly.