OutFront Forums
     Home    Register     Search      Help      Login    

Sponsors
Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax
Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.
Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Follow Us
On Facebook
On Twitter
RSS
Via Email

Recent Posts
Todays Posts
Most Active posts
Posts since last visit
My Recent Posts
Mark posts read

 

I want to shrink my code & make it reusable

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP, PHP, and Database >> I want to shrink my code & make it reusable
Page: [1]
 
 
barking mad

 

Posts: 287
Joined: 12/6/2002
From: Out in the sticks, UK
Status: offline

 
I want to shrink my code & make it reusable - 3/14/2009 15:16:42   

I have an online questionnaire with many questions, but rather than forver typing all teh form code can it be shortened & if so how please.
Here's an excerpt


<%
const qemployee1 = "did you have a company car?"
const qemployee2 = "do you receive other benefits from your employer?"
const qemployee3 = "do you contribute to a pension from your salary?"
const qemployee4 = "have you changed jobs this tax year?"
const qemployee5 = "do you have more than one job?"

const leftcol = "<tr><td class='left'>"
const midcol = "</td><td class='right'>"
const rightcol = "</td></tr>"


%>

<% 
question = qemployee1
inputfield = "employee1"
response.write leftcol & question & midcol & " yes <input name='" & inputfield & "' type='radio' value='1' /> no <input name='" & inputfield & "' type='radio' value='0' checked />" & rightcol

question = qemployee2
inputfield = "employee2"
response.write leftcol & question & midcol & " yes <input name='" & inputfield & "' type='radio' value='1' /> no <input name='" & inputfield & "' type='radio' value='0' checked />" & rightcol

question = qemployee3
inputfield = "employee3"
response.write leftcol & question & midcol & " yes <input name='" & inputfield & "' type='radio' value='1' /> no <input name='" & inputfield & "' type='radio' value='0' checked />" & rightcol

question = qemployee4
inputfield = "employee4"
response.write leftcol & question & midcol & " yes <input name='" & inputfield & "' type='radio' value='1' /> no <input name='" & inputfield & "' type='radio' value='0' checked />" & rightcol

question = qemployee5
inputfield = "employee5"
response.write leftcol & question & midcol & " yes <input name='" & inputfield & "' type='radio' value='1' /> no <input name='" & inputfield & "' type='radio' value='0' checked />" & rightcol

%>




basically I want to be able to feed the parameters into a subroutine (or something) and have it display the info , so something like

response.write yesnoquestion

where yesnoquestion generates the code to be used.

... and if you were being really clever create a loop which changes the number fo rthe variable to be used!


Any ideas?

_____________________________

The more I ask, the more I learn, the more I' m confused, therefore the more I ask ...
Spooky

 

Posts: 26720
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: I want to shrink my code & make it reusable - 3/16/2009 0:19:06   
You could use an array perhaps?
That would loop through the array until it reaches a specified count.

qemployee(0) = "did you have a company car?"
qemployee(1) = "do you receive other benefits from your employer?"
etc......


For i = 0 to maxcount(of array)

response.write leftcol & question(i) & midcol & " yes <input name='" & inputfield(i) & "' type='radio' value='1' /> no <input name='" & inputfield(i) & "' type='radio' value='0' checked />" & rightcol

Next




_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

Sp:)ky


(in reply to barking mad)
Page:   [1]

All Forums >> Web Development >> ASP, PHP, and Database >> I want to shrink my code & make it reusable
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts