Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Display Image on a condition

Posted on 2004-09-01
14
Medium Priority
?
213 Views
Last Modified: 2012-06-27
Hello
I have some scanned signature images in a folder. My Asp Page has a Selection Box with some names.I want to display the scanned signature image in the ASP page depending on the user selecting the name.Also can I submit that image to another page through a form?
Thanks
Venu
0
Comment
Question by:venukalikota
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
14 Comments
 
LVL 4

Expert Comment

by:MrClean21
ID: 11952602
Hi venukalikota,

    You can do it with javascript like :

    <select id='Name' onchange='changeImage(this)'>
    ...
    </select>

    <script>
    function changeImage(elem) {
        sign = document.getElementById("signature");
        sign.src = "http://www.com/images/" + elem.value() + ".jpg";
    }
    </script>

    To pass the value to another page, just set the value of an hidden field to the selected name.

MrClean
0
 

Author Comment

by:venukalikota
ID: 11954146
MrClean21
Do you know how to do this in VbScript? If i use the above code iam getting the error "Object does not support this property or method" when I select a name from the select box
0
 
LVL 4

Expert Comment

by:MrClean21
ID: 11954855
Sorry,

Here's the good one..

 function changeImage(elem) {
        sign = document.getElementById("signature");
        sign.src = "http://www.com/images/" + elem.value + ".jpg";
    }

in VBScript, it looks like this :

 function changeImage(elem)
        sign = document.getElementById("signature");
        sign.src = "http://www.com/images/" + elem.value + ".jpg";
 end function
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:venukalikota
ID: 11955404
Gives the error
Char: 2
Error: Object does n't support this property or method: 'elem.value'
code: 0

Further help would be appreciated
Thanks
0
 
LVL 4

Expert Comment

by:MrClean21
ID: 11955923
venukalikota,

using vbscript, you should reference the function like

<select id='Name' onchange='changeImage(me)'>


 function changeImage(elem)
        set sign = document.getElementById("signature")
        sign.src = "http://www.com/images/" + elem.value + ".jpg"
 end function

with an image with an id of signature like :

<img id="signature" src="blank.jpg">
0
 

Author Comment

by:venukalikota
ID: 11956346
Image tag has the id ="signature". That does n't work
0
 
LVL 4

Expert Comment

by:MrClean21
ID: 11957215
here's the complete test page that works for me :

<html>
<body>
<script language="vbscript">
function test(elem)

   msgbox elem.value

    set sign = document.getElementById("signature")
    sign.src = "http://www.com/images/" + elem.value + ".jpg"

end function
</script>

<select id="sel" onchange="test(me)">
      <option></option>
      <option value="1">1</option>
      <option value="2">3</option>
      <option value="3">4</option>
</select>

<img id="signature" src="">
</body>
</html>
0
 

Author Comment

by:venukalikota
ID: 11957829
My code looks like this and does not seem to work. Getting Type Mismatch error.it will not display the msgbox. If i remove the signature it gives the error "object required: 'sign' ". I have also tried using elem.value. It gives the error "object does not support this method or property: 'elem.value'

<%
Function getSupName()
      rs.Open cn.Execute("SELECT RFullName, RFirst, RLast FROM Resources WHERE RInactive = 0 AND (InstSup = 1) AND (EntityCode = 'SE')ORDER BY RFullName")  
      image = CStr(rs.Fields("RLast"))
    Response.Write("<select id=InstSupName name=InstSupName onchange='changeImage(image)' title='Select Supervisor' style='FONT-FAMILY: verdana'>")
      Do Until rs.EOF
      Response.Write("<option value='" & rs.Fields("RFullName") & "'>" & rs.Fields("RFullName") & "</option>")
      rs.moveNext
      Loop
      Response.Write("</select>")
End Function
%>

<html>
<head>
<script ID="clientEventHandlersVBS" LANGUAGE="vbscript">
<!--
Function changeImage(elem)
msgbox elem
sign = document.getElementById("signature")
sign.src = "../ASP/" + elem + ".bmp"
End Function
-->
</script>

</head>
<form id="FORM1" method="post" name="FORM1">
<body>
<table align="center" border="0" cellPadding="1" cellSpacing="1" width="100%" height="25%" valign="center" background tabIndex="0" >
<tr>
          <td colSpan="2">
            <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Installation REP:
                  <%=getSupName()%>
                </p><td colSpan="2">
                <img id="signature" name="signature" src="../ASP/Chris.bmp" height=50 width=200>
                </td>
        </tr>
</table>
</body>
</form>
</html>
0
 
LVL 4

Accepted Solution

by:
MrClean21 earned 1000 total points
ID: 11957889
Hi,

This code should work:

<%
Function getSupName()
     rs.Open cn.Execute("SELECT RFullName, RFirst, RLast FROM Resources WHERE RInactive = 0 AND (InstSup = 1) AND (EntityCode = 'SE')ORDER BY RFullName")  
     image = CStr(rs.Fields("RLast"))
    Response.Write("<select id=InstSupName name=InstSupName onchange='changeImage(me)' title='Select Supervisor' style='FONT-FAMILY: verdana'>")
     Do Until rs.EOF
     Response.Write("<option value='" & rs.Fields("RFullName") & "'>" & rs.Fields("RFullName") & "</option>")
     rs.moveNext
     Loop
     Response.Write("</select>")
End Function
%>

<html>
<head>
<script ID="clientEventHandlersVBS" LANGUAGE="vbscript">
<!--
Function changeImage(elem)
msgbox elem.value
sign = document.getElementById("signature")
sign.src = "../ASP/" + elem + ".bmp"
End Function
-->
</script>

</head>
<form id="FORM1" method="post" name="FORM1">
<body>
<table align="center" border="0" cellPadding="1" cellSpacing="1" width="100%" height="25%" valign="center" background tabIndex="0" >
<tr>
          <td colSpan="2">
            <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Installation REP:
               <%=getSupName()%>
              </p><td colSpan="2">
              <img id="signature" name="signature" src="../ASP/Chris.bmp" height=50 width=200>
              </td>
        </tr>
</table>
</body>
</form>
</html>


You must send the dropdown to the function.

MrClean
0
 

Author Comment

by:venukalikota
ID: 11958050
I changed the code the msgbox displays correctly but
Still gives the error "Object Required: 'sign' ". I think it is some how not considering the signature as an object on the form.
0
 
LVL 4

Expert Comment

by:kssaran
ID: 11960204
This works fine

<%
      strConn = "Provider=SQLOLEDB; "
      strConn = strConn & "Data Source=Atlas; "
      strConn = strConn & "Initial Catalog=tms; "
      strConn = strConn & "User Id=leaveuser; "
      strConn = strConn & "Password=userleave"
set cn = server.createobject("adodb.connection")
set objRs = server.createobject("adodb.connection")

Function getSupName()
       cn.open strConn
       strSql = "SELECT RFullName, RFirst, RLast FROM Resources WHERE RInactive = 0 AND (InstSup = 1) AND (EntityCode = 'SE') ORDER BY RFullName"
     set objRs = cn.Execute(strSql)
'     image = CStr(objRs.Fields("RLast"))
     Response.Write("<select id=InstSupName name=InstSupName onchange='changeImage(this)' title='Select Supervisor' style='FONT-FAMILY: verdana'>")
     Do Until objRs.EOF
            Response.Write("<option value='" & objRs.Fields("RFullName") & "'>" & objRs.Fields("RFullName") & "</option>")
          objRs.moveNext
     Loop
     Response.Write("</select>")
End Function
%>

<html>
<head>
<script LANGUAGE="javascript">
<!--
function changeImage(imgName)
 {
   if (document.images)
    {
      document['signature'].src= "../ASP/" + imgName.value + ".gif";
    }
 }
//-->
</script>

</head>
<form id="FORM1" method="post" name="FORM1">
<body>
<table align="center" border="0" cellPadding="1" cellSpacing="1" width="100%" height="25%" valign="center" background tabIndex="0" >
<tr>
          <td colSpan="2">
            <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Installation REP:
               <%=getSupName()%>
              </p><td colSpan="2">
              <img id="signature" name="signature" src="../ASP/Chris.bmp" height=50 width=200>
              </td>
        </tr>
</table>
</body>
</form>
</html>
0
 
LVL 4

Expert Comment

by:MrClean21
ID: 11962807
Since the sign is the object of the image tag, you must use set :

set sign = document.getElementById("signature")
sign.src = "../ASP/" + elem + ".bmp"

MrClean
0
 

Author Comment

by:venukalikota
ID: 11972743
Thank you very much MrClean. Works everything fine now. I appreciate your great help.
0
 
LVL 4

Expert Comment

by:MrClean21
ID: 11972751
It's been a pleasure to help you.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question