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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[DYNAMIC ASP PAGE (Use subroutine ?) ?

Status
Not open for further replies.

JonathanG6SWJ

Programmer
Joined
Jan 18, 2005
Messages
39
Location
GB
Help! I'm struugling with ASP/VBScript/JavaScript.

I am desinging a web page that will collect responses to a questionnaire. The question text and answers are stored in a mySql DB. As the user completes the questionnaire the page needs to be dynamically redrawn getting next block of questions from the DB and store the responses just made.

I'm pretty much OK with how to do the above! (I'll eat my hat later)but I want to reuse blocks of HTML code used to draw a table using new updated variable data of output from DB. I need to place a section header before a block of questions (section will all be different sizes)

So if you're still awake --- my basic question is how to reuse blocks of HTML including some asp without rewriting text for a second time. Can I call a subroutine with a mix of asp & html ?
 
If I understand your question, then the answer is yes. You can response.write your HTML code. For example (modify as you need):
Code:
<%
response.write ("<select name='test'>")
for i = 0 to rs.recordcount - 1
  response.write ("<option name='" & rs.fields("field1") & "'>field1</option>")
next
%>

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
Not sure if you'll like it but...
Try playing with dynamic html templates.
I like to use them because they can be edited in Dreamweaver or FP visually.
You can dynamically change html templates.
(Create my1.htm & my2.htm with different layouts and call them from my.asp depending on some variable).
To try the example below use:

(or type=3)

You'll be reusing the same html code for displaying different data

---------------------------------------------------
first file

my.htm
____________________________________________
<html>
<head>
<title>{title}</title>
<link rel="stylesheet" type="text/css" href="{style}">
</head>
<body>

<table width="300" border="1" cellpadding="0" cellspacing="0" bordercolor="#999900" bgcolor="{tblColor}">
<tr>
<td height="23" align="center">
{information}
</td>
<td align="center">
{information}
</td>
<td align="center">
{information}
</td>
<td align="center">
{information}
</td>
</tr>
</table>
</body>
</html>
________________________________________________

second file

my.asp
________________________________________________

<%
Dim result
result = ReadTemplateFile ("includes\", "my.htm")

Dim myTitle
Dim myStyle
Dim myInfo, i
Dim tblColor
if request("type")="3"then
myInfo="3"
tblColor ="#FFFF00"
elseif request("type")="2" then
i=0
myInfo=i
for i=1 to 3

myInfo=myInfo & "<br>your DB data " & i
next
tblColor ="#FF0000"
else
myInfo="info"
end if
myTitle="dynamic page"
'REPLACE COMMENTS WITH DYNAMIC INFO
result = replace (result, "{title}", myTitle)
result = replace (result, "{style}",myStyle)
result = replace (result, "{information}", myInfo)
result = replace (result, "{tblColor}", tblColor)
'SEND THEM TO THE BROWSER
Response.Write(result)

Function ReadTemplateFile (FilePath, FileToOpen)

Dim fs, f, line
line = ""


set fs=CreateObject("scripting.filesystemobject")
If fs.FileExists(Request.ServerVariables(4) & FilePath & FileToOpen) Then
set f=fs.OpenTextFile(Request.ServerVariables(4) & FilePath & "\" & FileToOpen)
Do While not f.AtEndOfStream
line= line & f.ReadLine()
line= line & VbCrLf
Loop
f.Close
else
line= "The file " & Request.ServerVariables(4) & FilePath & FileToOpen & " was not found!"
end if
ReadTemplateFile = line

End Function
%>________________________________________________
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top