Skip to main content
This topic has been closed for replies.
Correct answer Steve Sommers

Use a hidden field instead of relying on the button value. Button values are only present if the user actually clicks the button. Using the form submit event via code or even the user pressing enter instead of clicking on the button will result is no button value being posted.

2 replies

BKBK
Community Expert
Community Expert
March 26, 2016

<cfif isdefined("form.button2")>

06 <!--- Do somthing Here--->

07 </cfif>

<cfif isdefined("form.fieldnames")><!--- Form submitted --->

    <cfif isdefined("form.button2")>

    <!--- Button submission --->

    <cfelse>

    <!--- Javascript submission--->

    </cfif>

</cfif>

WolfShade
Legend
March 28, 2016

If I may be a bit pedantic.

<cfif StructKeyExists(form,"fieldnames")>

I've heard of  isDefined() giving false responses.

HTH,

^_^

BKBK
Community Expert
Community Expert
March 28, 2016

WolfShade wrote:

<cfif StructKeyExists(form,"fieldnames")>

I've heard of  isDefined() giving false responses.

As far as I know, isDefined("form.someFieldname") is practically equivalent to  structKeyExists(form,"someFieldname").

Steve SommersCorrect answer
Legend
March 25, 2016

Use a hidden field instead of relying on the button value. Button values are only present if the user actually clicks the button. Using the form submit event via code or even the user pressing enter instead of clicking on the button will result is no button value being posted.

Heff2000Author
Known Participant
March 28, 2016

That worked great!!!

changed my code to be the following and all works perfect  now.

I just check formfield savesw for the value "getorder"

Thank you

<cfdump var="#form#" label="testit">

02

<cfform name="testit" action="test.cfm">

<cfinput name="savesw"  type="hidden" value="ss" />

03<select name='myfield' onchange='submitit()'>
04  <option selected="selected"> --- Pick Drink ---</option>
05  <option >Milk</option>
06  <option>Coffee</option>
07  <option>Tea</option>
08</select>
09

</cfform>


<script language="JavaScript">

function submitit()

{

   document.getElementById('savesw').value='getorder' ;

   document.testit.submit();

}

<script>