|
 |
asp_components thread: input type image
Message #1 by moulot@k... on Wed, 07 Feb 2001 08:41:59 +0100
|
|
hi all,
i have a form with several <input type=" image"> and i would like to
detect which button the user presses. the problem is that with the type
image the value is null for all of them.
any help will be appriciated.
thanks in advance
Message #2 by Imar Spaanjaars <Imar@S...> on Wed, 07 Feb 2001 12:13:33 +0100
|
|
Hi Georges,
What code are you using for the type="image" ?? Do you give it a NAME as
well? Here is something that works for me:
<form id="frmTest" method="post">
<INPUT type="text" id="txtTest" name="txtTest"><BR>
<INPUT type="image" value="Submit" id="btnSubmit1"
name="btnSubmit1" SRC="images/test.gif">
<INPUT type="image" value="Submit" id="btnSubmit1"
name="btnSubmit1" SRC="images/test.gif">
</form>
Now, whenever this form is submitted, you'll receive either the x and y
coordinates of btnSubmit1 or for btnSubmit2.
So you could test it in a little if then construction:
if btnSubmit1.x <> "" then
' btnSubmit1 pressed
end if
if btnSubmit2.x <> "" then
' btnSubmit2 pressed
end if
Here is a little debug function I use to print the contents of the form
collection
sub DebugFormCollection()
Response.Write("<H2> Form Collection </h2>")
For Each Item in Request.Form
For iloop = 1 to Request.Form(Item).Count
Response.Write("<STRONG>" & Item & "</strong> = "
& Request.Form(Item)(iloop) & "<BR>")
Next
Next
end sub
When I run this on top of the page after the page was submitted, I receive
something like this:
txtTest = Test
btnSubmit1.x = 119
btnSubmit1.y = 196
The numbers are the X and Y coordinates of the location I clicked on the image.
The key to all this is that your image needs a unique name attribute. If
you omit that, you'll only receive the x and y coordinates, so you can't
determine on which image was clicked.
HtH
Imar
At 08:41 AM 2/7/2001 +0100, you wrote:
>hi all,
>i have a form with several <input type=" image"> and i would like to
>detect which button the user presses. the problem is that with the type
>image the value is null for all of them.
>any help will be appriciated.
>thanks in advance
Message #3 by moulot@k... on Wed, 07 Feb 2001 11:51:26 +0100
|
|
Imar,
thanks a lot; it works very well!!
just one more thing: can you give me the exact syntax in the if statement : if
btnSubmit1.x <> "" then
cause writing just btnSubmit1.x creates an error!
thanks, Georges
Imar Spaanjaars a écrit :
> Hi Georges,
>
> What code are you using for the type="image" ?? Do you give it a NAME as
> well? Here is something that works for me:
>
> <form id="frmTest" method="post">
> <INPUT type="text" id="txtTest" name="txtTest"><BR>
> <INPUT type="image" value="Submit" id="btnSubmit1"
> name="btnSubmit1" SRC="images/test.gif">
> <INPUT type="image" value="Submit" id="btnSubmit1"
> name="btnSubmit1" SRC="images/test.gif">
> </form>
>
> Now, whenever this form is submitted, you'll receive either the x and y
> coordinates of btnSubmit1 or for btnSubmit2.
> So you could test it in a little if then construction:
>
> if btnSubmit1.x <> "" then
> ' btnSubmit1 pressed
> end if
> if btnSubmit2.x <> "" then
> ' btnSubmit2 pressed
> end if
>
> Here is a little debug function I use to print the contents of the form
> collection
>
> sub DebugFormCollection()
> Response.Write("<H2> Form Collection </h2>")
> For Each Item in Request.Form
> For iloop = 1 to Request.Form(Item).Count
> Response.Write("<STRONG>" & Item & "</strong> = "
> & Request.Form(Item)(iloop) & "<BR>")
> Next
> Next
> end sub
>
> When I run this on top of the page after the page was submitted, I receive
> something like this:
>
> txtTest = Test
> btnSubmit1.x = 119
> btnSubmit1.y = 196
>
> The numbers are the X and Y coordinates of the location I clicked on the image.
>
> The key to all this is that your image needs a unique name attribute. If
> you omit that, you'll only receive the x and y coordinates, so you can't
> determine on which image was clicked.
>
> HtH
>
> Imar
>
> At 08:41 AM 2/7/2001 +0100, you wrote:
> >hi all,
> >i have a form with several <input type=" image"> and i would like to
> >detect which button the user presses. the problem is that with the type
> >image the value is null for all of them.
> >any help will be appriciated.
> >thanks in advance
>
Message #4 by Imar Spaanjaars <Imar@S...> on Wed, 07 Feb 2001 14:37:30 +0100
|
|
Hmmmmm, I think I forgot something. Sorry.
It should be:
Request.Form("btnSubmit1.x") when the method of the form is POST or
Request.QueryString("btnSubmit1.x") when either the method is left out, or
the method is GET.
Also, in my FORM example, I gave both buttons the same name. That should
have been two different names (Too much copy and paste ;-))
Here's how it should have looked:
<form id="frmTest" method="post">
<INPUT type="text" id="txtTest" name="txtTest"><BR>
<INPUT type="image" value="Submit" id="btnSubmit1"
name="btnSubmit1" SRC="images/test1.gif">
<INPUT type="image" value="Submit" id="btnSubmit2"
name="btnSubmit2" SRC="images/test2.gif">
</form>
Both images have a unique NAME attribute.
Imar
At 11:51 AM 2/7/2001 +0100, you wrote:
>Imar,
>thanks a lot; it works very well!!
>just one more thing: can you give me the exact syntax in the if statement : if
>btnSubmit1.x <> "" then
>cause writing just btnSubmit1.x creates an error!
>thanks, Georges
Message #5 by "Wally Burfine" <oopconsultant@h...> on Wed, 07 Feb 2001 14:30:26 -0000
|
|
You might try:
<input type=" image" id=image1 onclick="fnOnClick('image1')">
at that point you can do what ever you need to do and you know where it came
from.
>From: moulot@k... (Georges Moulot)
>Reply-To: "ASP components" <asp_components@p...>
>To: "ASP components" <asp_components@p...>
>Subject: [asp_components] input type image
>Date: Wed, 07 Feb 2001 08:41:59 +0100
>
>hi all,
>i have a form with several <input type=" image"> and i would like to
>detect which button the user presses. the problem is that with the type
>image the value is null for all of them.
>any help will be appriciated.
>thanks in advance
>
>
Message #6 by moulot@k... on Wed, 07 Feb 2001 15:39:39 +0100
|
|
Imar,
thanks alot it works fine.
Georges
Message #7 by Chao Zhou <ChaoZhou@e...> on Thu, 8 Feb 2001 12:17:42 -0500
|
|
Use javascript to control the actions on client side. I use image buttons in
such a way as shown below.
<html>
<head>
<script language="JavaScript">
function doSubmit(){
//do something
document.test.submit();
}
function doSubmit(){
document.test.reset();
}
</script>
</head>
<body>
<form method="post" action="test2.asp" name="test">
<input type="image" src="/images/sub_submit.gif"
onclick="JavaScript:doSubmit()">
<input type="image" src="/images/sub_cancel.gif"
onclick="JavaScript:doCancel()">
<!-- an alternative to image button -->
<a href="javascript:doSubmit()"><img src="/images/sub_submit.gif"
border="0"></a>
<a href="javascript:doCancel()"><img src="/images/sub_cancelt.gif"
border="0"></a>
</form>
</body>
</html>
hope it helpful.
Chao Zhou
-----Original Message-----
From: moulot@k... [mailto:moulot@k...]
Sent: Tuesday, February 06, 2001 11:42 PM
To: ASP components
Subject: [asp_components] input type image
hi all,
i have a form with several <input type=" image"> and i would like to
detect which button the user presses. the problem is that with the type
image the value is null for all of them.
any help will be appriciated.
thanks in advance
---
http://www.asptoday.com - the leading site for timely,
in-depth information for ASP developers everywhere.
$subst('Email.Unsub')
|
|
 |