Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Using an image as submit button

Hello,
I am displaying several (this will vary) thumbnails to user as a result of a query.  I am using the images as submit buttons. I want user to be able to click on thumbnail image and be taken to the appropriate page.

My problem is that I can't seem to pass the image value to the next page.  Can this be done?  This is what my code looks like so far.

Thanks

Mike



<%@ Language=VBScript %>

<%
Dim openConnection
Dim rsBaskets
dim strBasketName
dim strThumbnail
dim strTemp
dim strName
strTemp = "yes"

set openConnection = Server.CreateObject("ADODB.CONNECTION")
set rsSWbaskets = server.CreateObject("ADODB.Recordset")
openConnection.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Inetpub\wwwroot\newsite\dataOne.mdb"
set rsSWbaskets = openConnection.Execute("Select * FROM basket WHERE birthday LIKE '" & strTemp & "' ")
rsSWbaskets.MoveFirst

%>

<HTML><HEAD><TITLE>Sample</TITLE></HEAD>
<BODY>
<FORM NAME ="BetaMax" Method=Post Action="testo.asp">
     
<% While not rsSWbaskets.EOF %>

  <%
    strThumbnail = rsSWbaskets("thumbnail")
    strName = rsSWbaskets("name")
  %>
  <CENTER>
     <INPUT TYPE ="IMAGE" NAME="imgSearch" VALUE="<%=strThumbnail%>" src=<%=strThumbnail%>  width="100" height="100">
     <br>
  <h3><%Response.Write strName %>
      <br>
      </H3></CENTER>
     
<% rsSWbaskets.movenext
   Wend
%>
     
<%
  rsSWbaskets.close
  openConnection.Close
  set rsSWBaskets = nothing
  set openConnection = nothing
%>
</CENTER></form></BODY>
</HTML>
0
MichaelVB
Asked:
MichaelVB
  • 4
  • 3
  • 3
  • +3
1 Solution
 
daniel_cCommented:
<INPUT TYPE ="IMAGE" NAME="imgSearch" VALUE="<%=strThumbnail%>" src=<%=strThumbnail%>  width="100"
height="100" OnClick="document.BetaMax.submit();">
0
 
MichaelVBAuthor Commented:
This does get me to the next page.  However, the VALUE, strThumbnail, does not get passed.  Here is the page I am using to test this.

Thanks alot.

Mike

<%@ Language=VBScript %>

<%

     dim strVariable
     strVariable = Request.Form("imgSearch")

%>
<HTML>

<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>


<% Response.Write(strVariable) %>

<P>&nbsp;</P>

</BODY>
</HTML>
0
 
mgfranzCommented:
I don't think you can put a value on an input type=image tag daniel, this is a typical <image> submit tagline;

<input type=image src=<%=strTHumbNail%>>

If you put the <value> in a hidden field it will work.

But why not just use something like this?

<a href="testTo.asp?varVal=<%=strThumbnail%>"><immg src="<%=strThumbnail%>"></a>
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
hongjunCommented:
<input type="image"> will only return you the x and y coordinates clicked. Use a hidden field like what mgfranz suggested. Then get the value of the hidden field in your page specified in your form action. That will work

hongjun
0
 
anupkaradeCommented:
Hi buddy..
      According to the secenario presented by you
      I think the better idea is to use the thumbnails as
      links and pass the value as querystring to the
      target page... This is usually done in all shopping
      cart type of application...Use the image tag

      here is the code
   
     
   <a href="testPage.asp" target=_blank><img src=<%=strThumbnail%> value="<%=strThumbnail%>"></a>



this works fine...
                                 regards
                                         Anup
0
 
ravi_raj123Commented:
HI,
If you have to submit any other values other then the image name, then the above said method i.e. hyperlink method won't work, you have to pass all the values through query string,so try this way... this way you can submit the whole form values without doing much work.

<script language="javascript">
function gopage(pagename) {

    document.frm.action="page.asp?pagename=" + pagename;
    document.frm.submit();
}
</script>
<form name="frm" method="post">
<input type="image" src=<%=strThumbnail%> value=<%=strThumbnail%> onclick="gopage(this.value)">
</form>


Good Luck...:)
0
 
ravi_raj123Commented:
Oops!!! I made a mistake in the above answer. SORRY

Here is the correct one.

<script language="javascript">
function gopage(pagename) {

   document.frm.pn.value=pagename
   document.frm.submit();
}
</script>
<form name="frm" method="post" action="gopage.asp">
<input type="image" src=<%=strThumbnail%> value=<%=strThumbnail%> onclick="gopage(this.value)">
<input type="hidden" name="pn">
</form>

Sorry once again for the previous answer.
0
 
daniel_cCommented:
mqfranz, I just copy and paste from MichaelVB's code.
The concept that I actually wanted to give is that you can use OnClick event, but anyway mqfranz's suggestion makes sense! :)
0
 
MichaelVBAuthor Commented:
mgfranz,

First let me thank you for your help. I'm trying to use your suggestion but I'm still having a problem.

This is what my code looks like
<A HREF="testo.asp" varVal=<%=strThumbnail%>"><img src="<%=strThumbnail%>"></a>

My question is that I am not sure how to retrieve the value of varVal in testo.asp

This is what I am trying to do:
strVariable = Request.Form("varVal")

This doesn't work... Doesn't the Request object need the name of an <INPUT> tag?  If so, what would I use in this case?  

Thanks again.

Mike
0
 
hongjunCommented:
Does you address bar displays the querystring after the link is clicked?

hongjun
0
 
hongjunCommented:
Sorry miss that.

TRY THIS
strVariable = Request.QueryString("varVal")

MUST WORK!

hongjun
0
 
hongjunCommented:
And this if your name of the asp is testTo.asp
<A HREF="testTo.asp?varVal=<%=strThumbnail%>"><img src="<%=strThumbnail%>"></a>


Or if it is testo.asp
<A HREF="testo.asp?varVal=<%=strThumbnail%>"><img src="<%=strThumbnail%>"></a>


You seems to have conflicting name of the asp file.

hongjun
0
 
mgfranzCommented:
Thanks for speaking for me hongjun, want to pay my bills too?

Mike,

"This is what my code looks like
<A HREF="testo.asp" varVal=<%=strThumbnail%>"><img src="<%=strThumbnail%>"></a>"

This is what is should look like;

<a href="testto.asp?varVal=<%=strThumbnail%>"<img src="<%=strThumbnail%>" border=0></a>

"My question is that I am not sure how to retrieve the value of varVal in testo.asp

This is what I am trying to do:
strVariable = Request.Form("varVal")"

You can retrieve it with a simple Request(), ASP uses QueryString by default;

strVariable = Request("varVal")

Mark



0
 
MichaelVBAuthor Commented:
Worked like a charm. Thanks again for your help.
Mike
0
 
mgfranzCommented:
Welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now