I've been tagged [This link opens in a new window]

How to know if a input type image has been pressed in ColdFusion

It's easy to know when a form has been submitted when you have only one submit button on your page, it's even as easy if you have more than one submit button on your page to know which one was pressed. But what about if you have more than one image button on your page, well it is just as easy, but from experience, I have found a lot of people don't know how to do this, so that makes this article worthwhile!

With a standard <input type="submit" name="btn1" value="Go" /> you just look for the button name like: <cfif isDefined("form.btn1")></cfif>, and the same goes for multiple submit buttons.

With <input type="image" src="image.gif" name="btn1" alt="" title="" /> it is just as easy, but you just need to add one more thing to your isDefined() and that is .x. So instead of <cfif isDefined("form.btn1")></cfif> you will have <cfif isDefined("form.btn1.x")></cfif>.

You can look for .y instead if you want, but it makes no difference. The reason it works in this way is because when you press an image button, the browser sends the coordinates for that press instead of the button name. Then in ColdFusion, all you need to do is look for the coordinates, hence the x, y values.

  • Del.icio.us [This link opens in a new window]
  • Digg [This link opens in a new window]
  • Technorati [This link opens in a new window]
  • Reddit [This link opens in a new window]
  • Stumble Upon [This link opens in a new window]
  • Furl [This link opens in a new window]