Mar
30

Coordinates of an input type image

5 comments Posted by: Nahuel

In my previous post, Paul Hastings asked how to capture the x,y from a clicked image. In response to that, I made a small workaround that requires an invisible text field.

This is not the cleanest way to do it and I'm sure someone will come up with a simpler solution.

So here it is:

<cfsavecontent variable="actionSend">
   myImageCoords.text = "x:"+myImage._xmouse+" | y:"+myImage._ymouse;
   submitForm();
</cfsavecontent>

<cfform name="myform" height="300" width="300" format="Flash">
   <cfinput type="text" visible="false" height="1" name="myImageCoords" width="160">
   <cfinput type="image" height="211" onClick="#actionSend#" src="images/school.jpg" name="myImage" width="160">
</cfform>

View example
Download the source

Category: CFForm | ColdFusion |

5 Comments so far

Write yours
Tim
1. Tim wrote on March 30, 2006 at 10:47 AM
Can someone look at this and tell me why the submitForm(); does not work anymore?

My CFC returns a numeric 1 if the date test was good.

i want it to validate the other fields first then do a date compare of 2 date type input fields to make sure the start is not after the end date.

I originaly tried this with just AS but it dosnt work if the dates are in different years.


thanks in advance

var formvalid = mx.validators.Validator.isStructureValid(this, 'vacreq');
var startdate = startdate;
var enddate = enddate;
var vacreq = vacreq;
var d1:Date = startdate.text;
var d2:Date = enddate.text;
&lt;cfoutput&gt;#conn#&lt;/cfoutput&gt;
var tdService:mx.remoting.NetServiceProxy;
var tdHandler = {};

tdHandler.onResult = function(results:Object):Void {
if (results == 1){
   submitForm();
} else {
alert(&quot;Invalid Starting and Ending dates.&quot;);   
}

};
tdHandler.onStatus = function(stat:Object):Void{alert(&quot;Error while calling cfc:&quot; + stat.description);}

tdService = connection.getService(&quot;CFC.pto&quot;, tdHandler);

if(formvalid){
   tdService.testDates(d1,d2)
} else {
   userOnError();

}
Tim
2. Tim wrote on March 30, 2006 at 10:51 AM
I forgot to add a few things to my post,
everything works except the submitForm();
my cfc works because i get the alert if the dates are bad.

I am sure this is something odvious that i am just not seeing.

Thanks for all the hard work here. wonderful reference site.

Tim
Laura
Tim,
Inside the function, submitForm is out of scope. Use _root.submitForm() and it should work.
Holger
4. Holger wrote on August 17, 2006 at 10:04 AM
Hi Tim!

I have the seem problem with the dates! You could send or post me the complete example of this!

I've seem ideas, I call to cfcomponent but my problem is how recieved in actionscript and how connect with the cfcomponent!

Thanks!!
Tim
5. Tim wrote on August 17, 2006 at 11:53 AM
Hi,
Sorry i posted this here.
Laura, as usual you hit the nail on the head.
thanks
tim

The basis of this form is to allow users to request vacation. If the start and end dates are ok then the code i posted would allow the form to continue. otherwise it would alert the user about the bad dates.

Here is the CFC code i used to check the dates. I did this because my skill in AS is not that great and this seem much easier.
<cfargument name="st" required="yes" type="date">
<cfargument name="et" required="yes" type="date">
<cfargument name="stt" type="string" required="no" default="8:00">
<cfargument name="ett" type="string" required="no" default="16:00">
<cfset s = st & " " & stt>
<cfset e = et & " " & ett>
<cfset std = ParseDateTime(s)>
<cfset etd = ParseDateTime(e)>
<cfif dateCompare(std,etd,'h') GT 0>
   <cfset rnum = 2>
<cfelseif dateCompare(std,etd,'h') Eq 0>
   <cfset rnum = 4>
<cfelseif dateCompare(std,etd,'d') GT 0>
   <cfset rnum = 0>
<cfelseif dateCompare(std,etd,'d') LTE 0>
   <cfset rnum = 1>
<cfelse>
   <cfset rnum = -1>      
</cfif>
<cfreturn rnum>


I omitted my other code here, because its not releavent but it checks the users vacation data and makes sure that the number of days they are requesting is available to them to take. if not, then it sets rnum = 3.



in my form, in the function that is attached to the send button, in the Results of my testDate call:
if (results == 1){
   _root.submitForm();
} else {      
if(results == 0){
alert("Invalid Starting and Ending dates. Start date is later than the end date.");
} else if(results == 2){
alert("Invalid Starting and Ending times. Start time must be less than End time.");
} else if(results == 3){
alert("You have request more days off than allowed. Please adjust your selected dates.");
} else {
alert("Invalid Starting and Ending dates. Check to make sure the start and end times are not the same. And make sure the end date is after the start date.");      
      }
   }
};

Leave your comment

Comment etiquette: As a gesture to those subscribed to this post, please keep your comments relevant to the post.

Your email address will never be displayed.
Email is gravatar enabled.Gravatar are the pictures you see next to the comments. If you like to have one, visit gravatar



Allowed tags:

<code>
All other tags will be shown as such, when in doubt, use the preview.




Preview:

Refresh Preview
1. You wrote on