Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp if else and then

Status
Not open for further replies.

dorling

Technical User
Mar 25, 2004
80
GB
hi there,

i know this is very basic but i've never used ASP before!!

basic i need 5 button called button1, button2 and etc

and they need to change a image to button1.gif or button2.gif etc

very simple i know but how can i do this

can this be done with out reload the asp page



thanks in advance

Jonathan D
 
Have your form submit to the same page to refresh it. Use Request("btnname") to get a variable to use to specify what image to use.

Here is an example:

Code:
<%@ LANGUAGE="VBSCRIPT" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Yes No Test</title>
</head>
<body>
<%
AnswerYes = Request("btnYes")
AnswerNo = Request("btnNo")
If AnswerYes = "Yes" Then
	Response.Write "<Img src = 'images/Yes.jpg' Alt = 'The Answer Was Yes'>"
ElseIf AnswerNo = "No" Then
	Response.Write "<Img src = 'images/No.jpg' Alt = 'The Answer Was No'>"
Else
	Response.Write "Please Select An Answer"
End If
%>
	<p><input type="submit" value="Yes" name="btnYes"><input type="submit" value="No" name="btnNo"></p>
</form>
</body>
</html>


I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Hello dorling,

In a sense you can. But I don't readlly know what you mean. Here is one button. You save it as an asp to your server. Click to alter the image. Do you consider it ever reloading the asp?
Code:
<%
srcimg1=array("[URL unfurl="true"]http://tek-tips.com/images/logo.gif",[/URL] "[URL unfurl="true"]http://tek-tips.com/images/partnerbtn120x60.gif")[/URL]
%>

<html>
<head>
<script language="vbscript">
sub changeimg(selemid)
	set elem=document.getElementById(selemid)
	if elem.src="<%=srcimg1(0)%>" then
		elem.src="<%=srcimg1(1)%>"
	else
		elem.src="<%=srcimg1(0)%>"
	end if
	document.x.y.focus
end sub
</script>
</head>
<body>
<img id="img1" src="<%=srcimg1(0)%>"/><br>
image 1<br>
<form name="x" action="" method="">
<input type="button" name="y" value="alternative image-1" onclick="changeimg('img1')"/>
</form>
</body>
</html>
regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top