I didn't get Pauls solution to work with multiple buttons, but here is my solution without javascript (uses php instead): <input type='image' alt='img1' src='../images/img1.gif' name='img1' /> <input type='image' alt='img2' src='../images/img2.gif' name='img2' />
and to see which button the user clicked: if (isset($_POST['img1_x'])) { unset($_POST['img1_x'],$_POST['img2_y']); /* do whatever you wan't */ } else if (isset($_POST['img2_x'])) { unset($_POST['img2_x'],$_POST['img2_y']); /* again do whatever you wan't */ }
I have to unset the post values because the user can click first img1 then img2 then again img1 and i just simply sen the whole $_POST array so eventually it would contain both. And still don't get different values, but can play with the different names.
If anyone can make a simpler solution with php i'd be happy to here about it
I had this problem today when i was using a php variable as the value using the tag and sending it to another page using GET to be used for a MySQL query. It worked fine in FF but IE didnt want to know.
heres the code...
Thanks to this page giving me some ideas,
All i did was add this line to get it to work in IE...didnt need any javascript!
This is terrific! Thank you Jesse! I just used this solution and added the ability to get a value too. What you can do is add the value to the end of the name attribute seperated by a dash. For example if your name is "imagePressed" the new name would be "imagePressed-3". Then call the below function to extract it out.
function getImageButtonValue($formvars, $name) { // loop through the keys foreach ($formvars as $key => $value) { // if key is what you are looking for if (strstr($key, $name)) { // extract out the value from the name $temp = split('-', $key); // get rid of the _x or _y too $temp = split('_', $temp[(sizeof($temp)-1)]); return $temp[0]; } } // didn't find anything so return false. return false; }
Just becareful if your name attribute or value has dashes or underscores.
Comment
I didn't get Pauls solution to work with multiple buttons, but here is my solution without javascript (uses php instead):
<input type='image' alt='img1' src='../images/img1.gif' name='img1' />
<input type='image' alt='img2' src='../images/img2.gif' name='img2' />
and to see which button the user clicked:
if (isset($_POST['img1_x'])) {
unset($_POST['img1_x'],$_POST['img2_y']);
/* do whatever you wan't */
}
else if (isset($_POST['img2_x'])) {
unset($_POST['img2_x'],$_POST['img2_y']);
/* again do whatever you wan't */
}
I have to unset the post values because the user can click first img1 then img2 then again img1 and i just simply sen the whole $_POST array so eventually it would contain both. And still don't get different values, but can play with the different names.
If anyone can make a simpler solution with php i'd be happy to here about it
Parent comment
I had this problem today when i was using a php variable as the value using the tag and sending it to another page using GET to be used for a MySQL query. It worked fine in FF but IE didnt want to know. heres the code... Thanks to this page giving me some ideas, All i did was add this line to get it to work in IE...didnt need any javascript!
Replies
This is terrific! Thank you Jesse! I just used this solution and added the ability to get a value too. What you can do is add the value to the end of the name attribute seperated by a dash. For example if your name is "imagePressed" the new name would be "imagePressed-3". Then call the below function to extract it out.
<input type='image' name='imagePressed-3' src='/btn.gif'>
function getImageButtonValue($formvars, $name) {
// loop through the keys
foreach ($formvars as $key => $value) {
// if key is what you are looking for
if (strstr($key, $name)) {
// extract out the value from the name
$temp = split('-', $key);
// get rid of the _x or _y too
$temp = split('_', $temp[(sizeof($temp)-1)]);
return $temp[0];
}
}
// didn't find anything so return false.
return false;
}
Just becareful if your name attribute or value has dashes or underscores.
Hope this helps!