Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

determining which button was pressed on form 1

Status
Not open for further replies.

jgroove

Programmer
Jul 9, 2001
43
US
I have a form that submits to an action page that inserts/updates a database table depending on which button was pressed. How can I determine from the form which button was pressed?

 
Let me try to understand this, let's say you have a form with the buttons: UPDATE and DELETE.

And you want to execute an update or delete action depending on the wich button was pressed correct?

If that's the case here's an example:

====================================================
here are your input buttons:

<form action=&quot;selectAct.cfm&quot; method=&quot;post&quot;>
<input type=&quot;submit&quot; name=&quot;update&quot; value=&quot;UPDATE&quot;>
<input type=&quot;submit&quot; name=&quot;delete&quot; value=&quot;DELETE&quot;>
</form>

=====================================================

here's the &quot;selectAct.cfm&quot; page:

<cfif IsDefined(&quot;FORM.update&quot;)>
<!--- Run update query --->

<cfelseif IsDefined(&quot;FORM.delete&quot;)>
<!--- Run delete query --->

</cfif>

Let me know if this helps.
 
stevenng,

Thank you for responding. That is exactly what I am trying to do. I was trying by testing for whether the value was true or not. Like this....

<cfif FORM.update>
<!--- Run update query --->
<cfelseif FORM.delete>
<!--- Run delete query --->
</cfif>

After fixing this problem another one arose. The form page has the submit buttons as images. So in the form the buttons look like this....
<input type=&quot;Image&quot; name=&quot;update&quot; src=&quot;images/update.gif&quot;>
<input type=&quot;Image&quot; name=&quot;delete&quot; src=&quot;images/delete.gif&quot;>

Is there a way to find out which image was pressed?

jgroove
 
In this form:

<form action=&quot;test.cfm&quot; method=&quot;post&quot;>
<input type=&quot;Image&quot; name=&quot;update&quot; src=&quot;images/update.gif&quot;>
<input type=&quot;Image&quot; name=&quot;delete&quot; src=&quot;images/delete.gif&quot;>
</form>

Clicking the button would yield something similar to:

Form Fields:

FIELDNAMES=update.X,update.Y
update.X=24
update.Y=25

OR

Form Fields:

delete.X=24
delete.Y=25
FIELDNAMES=delete.X,delete.Y

Two values are of interest here:

update.x and update.y or delete.x and delete.y

To see if the user clicked a particular image submit button, use:

<CFIF IsDefined(&quot;FORM.update.x&quot;) OR IsDefined(&quot;FORM.update.y&quot;)>
...update statements go here...
<CFIF IsDefined(&quot;FORM.delete.x&quot;) OR IsDefined(&quot;FORM.delete.y&quot;)>
...delete statements go here...
</CFIF>

The x and y represent the Cartesian pixel coordinates within the image that the user clicked. So, Theoretically, you could have several actions based on the exact pixel the user clicked. - tleish
 
tleish,

Thank you so much. That was an excellent explantation.

jgroove
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top