Re: problem with image button
| From: | Chris Hayes | Date: | Sun, 24 Sep 2000 00:40:03 +0000 |
| Subject: | Re: problem with image button | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-18177@lists.php.net to get a copy of this message | ||
hi there Mark,
> Let's say I have a form with three image buttons:
> <input type=image name=add src="add.gif">
> <input type=image name=delete src="delete.gif">
> <input type=image name=update src="update.gif">
>
> when I process the form I want to see what button was pressed, but
> instead of add being set, add.x and add.y get set.
Unfortunately no JavaScript events can be captured over the form type
'image'. There are workarounds but they would make you dependable on whethet
people accept javascript por not.
<A HREF="javascript:someFunction()"><IMG SRC="someImage.gif"
onClick=someFunction()"></A>
Or
<A HREF="javascript:document.myform.submit()"><IMG
SRC="my_cool_and_amazing_button.gif" BORDER="0" WIDTH="16"
HEIGHT="16"></A>
!!!OR the one I would do:
<A HREF="javascript:'
change_value_of_some_hidden_field_to_the_word_ADD;
document.myform.submit();
'">
<IMG SRC="add.gif" BORDER="0" WIDTH="16"
HEIGHT="16">
</A>
(!-- remove hard returns in <A > tag for better effect --)
> now the question is: what's the best way to check which one is set
> since doing this:
>
> if(isset($add.x)) ...
>
> gives a parse error?
I do not understand the add.x and add.y story. At all. Where do they come
from?
I'm not an expert but what's the variable add.x? Horizontal position of the
image 'add' maybe? can one have a dot in a PHP variable name? what does a
dot mean to PHP on this position?
At http://developer.irt.org/script/169.htm you
can find something with
images.
If it where not pictures but buttons, i saw on the IRT.ORG javasscript FORM
faq:
----
Q: If I have two identically named submit buttons, but with different
values, how can I tell which one was pressed?
A:
<SCRIPT LANGUAGE="JavaScript"><!--
var button = 0;
function test(val) {
button = val;
}
function check() {
alert('Button ' + button + ' pressed');
}
//--></SCRIPT>
<FORM onSubmit="check()">
<INPUT TYPE="SUBMIT" NAME="xxxx" VALUE="Button 1"
onClick="test('1')">
<INPUT TYPE="SUBMIT" NAME="xxxx" VALUE="Button 2"
onClick="test('2')">
</FORM>
Maybe this helps you a step further.
And this one (same source) is bad news for your plans:
(remember, the suggestion involves a lot of javascript which may exclude
users. the first sentence in the answer seems to be the most important for
you)
----
Q: When using an image input type in a form how can I perform form
validation on form submission?
A:
The input type image, is not officially part of specification of a form.
The following script attempts to overcome this problem. Rather than using an
input type of image it uses a normal image link. The call to the check()
function invokes the validate() function to perform the normal validation.
The result then dictates whether the form is submitted using the submit()
method.
<SCRIPT LANGUAGE="JavaScript"><!--
function validate(myobject) {
if (myobject.mytext.value == "yes")
return true;
else
return false;
}
function check(myobject) {
if (validate(myobject))
myobject.submit();
}
//--></SCRIPT>
<FORM NAME="myform" onSubmit="return validate(document.myform)">
<INPUT TYPE="TEXT" NAME="mytext" VALUE="">
<A HREF="javascript:check(document.myform)"><IMG SRC="animages.gif"
BORDER="0" WIDTH="16" HEIGHT="16"></A>
</FORM>
------
Hope this helped....
Chrisy
--------------------------------------------------------------------
-- C.Hayes Droevendaal 35 6708 PB Wageningen the Netherlands --
--------------------------------------------------------------------