Jump to content

problem with input type='image'


onlyican

Recommended Posts

Hey people

 

I have a form full of buttons

Depending what button is pressed

I am using image buttons

Now I have hit a problem, in IE.

 

Example

I have 2 buttons

<input type='image' name='ImageButton1' value='X' src='images/ImageBtnA.gif' />
<input type='image' name='ImageButton2' value='Y' src='images/ImageBtnB.gif' />

 

Now the PHP Stuff

 

<?php
$ImgBtn1 = isset($_POST["ImageButton1"]) ? $_POST["ImageButton1"] : "";
$ImgBtn2 = isset($_POST["ImageButton2"]) ? $_POST["ImageButton2"] : "";

if($ImageBtn1 != ""){
//Do some code, for when this button is pressed
}
if($ImageBtn2 != ""){
//Do some code, for when this button is pressed
}

?>

 

NOTE: I need the value of this as well

 

In FF, this works fine

 

In IE, its not working

 

I don't print_r($_POST)

I get something like

ImageButton1_x => 2, ImageButton1_y => 6

 

(The X and Y values of where the button / image was pressed.

 

But I need the name and value of the button which was pressed.

 

Any ideas how to resolve this issue.


Link to comment
Share on other sites

Oh dear, doesn't anyone understand what image buttons are and how they work?

 

Image buttons work the same way as image maps - when clicked, they pass the x and y coordinate values of the click relative to the upper left corner of the image.  Magic! Just like the html standard.  Apparently IE complies and FF doesn't.

 

The way to tell if an image button has been clicked is to determine if the value of the x or y coordinate exists in the passed array from the form.

 

$_POST["ImageButton1"] doesn't do anything. The right (and working) way to do it is to test for $_POST['imageButton1_x'] (or _y).

Link to comment
Share on other sites

the understanding of how image inputs is not the issue - its really down to why use them...

 

MAC OS will put its own glass btton there anyway for image or submit.  IMO submit buttons are easier to deal with as they 'behave' the same cross browser - as already oted in this thread images act as image maps and are dealt with differently by differnt browsers.

 

So in order to reduce your workload I believe using the simple submit type is the way to go...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.