Link to home
Start Free TrialLog in
Avatar of MichaelVB
MichaelVB

asked on

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>
Avatar of daniel_c
daniel_c

<INPUT TYPE ="IMAGE" NAME="imgSearch" VALUE="<%=strThumbnail%>" src=<%=strThumbnail%>  width="100"
height="100" OnClick="document.BetaMax.submit();">
Avatar of MichaelVB

ASKER

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>
Avatar of Mark Franz
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>
<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
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
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...:)
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.
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! :)
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
Does you address bar displays the querystring after the link is clicked?

hongjun
Sorry miss that.

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

MUST WORK!

hongjun
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
ASKER CERTIFIED SOLUTION
Avatar of Mark Franz
Mark Franz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Worked like a charm. Thanks again for your help.
Mike
Welcome.