Skip to main content
This topic is closed to new replies. Start a new post to keep the conversation going.
Steve SommersCorrect answer
Legend
Mar 25, 2016 8:30 PM UTC

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.

10 replies

BKBK
Community Expert
Community Expert
Mar 26, 2016 8:11 PM UTC

<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>

Translate
WolfShade
Legend
Mar 28, 2016 1:51 PM UTC

If I may be a bit pedantic.

<cfif StructKeyExists(form,"fieldnames")>

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

HTH,

^_^

Translate
BKBK
Community Expert
Community Expert
Mar 28, 2016 4:22 PM UTC

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").

Translate
Steve SommersCorrect answer
Legend
Mar 25, 2016 8:30 PM UTC

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.

Translate
Heff2000Author
Known Participant
Mar 28, 2016 5:21 PM UTC

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>

Translate