Jump to content

Input Type Img


gar onn
 Share

Recommended Posts

I would like to use an input type image to get the coords clicked (progressed with PHP)<input name="action" id="action" type="image" src="url/to.img"> but... I want to send them with AJAX...anyone some ideas?

Link to comment
Share on other sites

Put an onclick handler on the image, or an onsubmit handler on the form (the onsubmit would probably be better), and in the handler have it write out the event information to the Firebug console and see if the coordinates are included. If it's the onclick handler, you'll probably find the coordinates somewhere in the event object. If it's the onsubmit handler, it might actually create new hidden form elements that have the coordinates. So in the handler send everything you can to the Firebug console, send the event object, any parameters to the handler, the form element, etc. e.g.:

function submit_handler(a, b, c, d){  console.log(a);  console.log(b);  console.log(c);  console.log(d);  console.log(window.event);  console.log(document.getElementById('form_id'));}

In that example, in some browsers the "a" parameter will be the event object, and in others it will be window.event.

Link to comment
Share on other sites

I forgot about something else, when you have a click event I believe that the event handler always includes the coordinates where the event happened, so you should be able to have an onclick handler on any element and get the coordinates from the event object.

Link to comment
Share on other sites

But that gives the coords from tthe windows topleft corner.I 've used this:

<form action='Jfpasout.php' name="action" target="dmp"><input name="coords" id="coords"><br/><input name="action" id="post" type="image" src="testzone.php?img" width="*"> <input name="map_s" value="action"></form><iframe style="display: none;" name="dmp" src="Jfpasout.php"></iframe>

and the PHP of Jfpasout.php

function mapcoordsname($name){$eline="\$value=\$_REQUEST['".$name."_x'].\"|\".\$_REQUEST['".$name."_y'];";eval($eline);return $value;}		$mapname=$_REQUEST['map_s'];		$value=mapcoordsname($mapname);		echo "<script>window.parent.document.".$mapname.".coords.value='$value'</script>";

and that works fine but tnx

Edited by gar onn
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...