Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 142
  • Last Modified:

Can I use ASP to insert a large block of HTML?

Hi,

I'm an ASP Noob Deluxe, but I'm slowly making progress.

I have a number of pretty long <select> boxes on my web form.  What I would like to do, is somehow store the option values from these in an ASP Variable or Function, and then just use that instead of having the list over and over again throughout my form.

Here is a sample list:

<select name="PackageYrs1" class="rating" style="width:43px" id="PackageYrs1" onFocus="playClick();" onChange="playClick();this.size=1;this.style.background='none';" tabindex=302>
<option selected value="0">0.0</option>
<option value="">-</option>
<option value="0.5">0.5</option>
<option value="1.0">1.0</option>
<option value="1.5">1.5</option>
<option value="2.0">2.0</option>
<option value="2.5">2.5</option>
<option value="3.0">3.0</option>
<option value="3.5">3.5</option>
<option value="4.0">4.0</option>
<option value="4.5">4.5</option>
<option value="5.0">5.0</option>
<option value="5.5">5.5</option>
<option value="6.0">6.0</option>
<option value="6.5">6.5</option>
<option value="7.0">7.0</option>
<option value="7.5">7.5</option>
<option value="8.0">8.0</option>
<option value="8.5">8.5</option>
<option value="9.0">9.0</option>
<option value="9.5">9.5</option>
<option value="10.0">10.0</option>
<option value="11.0">11.0</option>
<option value="12.0">12.0</option>
<option value="13.0">13.0</option>
<option value="14.0">14.0</option>
<option value="15.0">15.0</option>
<option value="16.0">16.0</option>
<option value="17.0">17.0</option>
<option value="18.0">18.0</option>
<option value="19.0">19.0</option>
<option value="20.0">20.0</option>
<option value="25.0">25.0</option>
<option value="30.0">30.0</option>
</select></p>

I would like to change it to:

<select name="PackageYrs1" class="rating" style="width:43px" id="PackageYrs1" onFocus="playClick();" onChange="playClick();this.size=1;this.style.background='none';" tabindex=302>
<%=strSelect_Years%>

Is that possile?

Thanks!
0
MitchellVII
Asked:
MitchellVII
  • 3
  • 2
2 Solutions
 
_Stilgar_Commented:
Of course.

Either store the options as text (Dim var : var = "<option selected value="0">0.0</option>..."), or create an array and populate it with the options in a nice way. then use a for loop to output this every time you need it.

Stilgar.
0
 
_Stilgar_Commented:
For example (the array option):

a(0)="0.0"
a(1)="-"
a(2)="1.0"
etc.

and then

<select name="PackageYrs1" class="rating" style="width:43px" id="PackageYrs1" onFocus="playClick();" onChange="playClick();this.size=1;this.style.background='none';" tabindex=302>
<%
For i=0 to UBound(a,1)
  response.write "<option value="""&a(i)&""">"&a(i)&"</option>" & vbCrlf
Next
%>

Don't forget to check a is not null if you're expecting empty arrays, and that you can contain all this within a global function.

Stilgar.
0
 
glennonrCommented:
Another option to storing it in a function would be to simply store the options in a stand alone file and then just include it where ever you want it.

Like this:

1. Create a text file that contains your options

<option selected value="0">0.0</option>
<option value="">-</option>
<option value="0.5">0.5</option>
<option value="1.0">1.0</option>
etc.

2. Save the text file as Options.inc

3. Everyplace where you want it to appear do something like this:
<select name="PackageYrs1" class="rating" style="width:43px" id="PackageYrs1" onFocus="playClick();" onChange="playClick();this.size=1;this.style.background='none';" tabindex=302>

<!--#include file="Options.inc"-->
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
MitchellVIIAuthor Commented:
Hi Stilgar,

Thanks for the quick response.  I need to assig the list to a variable rather than using arrays because many of these lists is a variety of words and would be easier to keep up with if just typed out.

Anyway, let's create a little example so I am sure got this:

Let say I wanted to assign the following list to a variable (assuming I do this in the <head> section):

<option selected value="0">0.0</option>
<option value="">-</option>
<option value="0.5">0.5</option>
<option value="1.0">1.0</option>
<option value="1.5">1.5</option>

Would I go:
<%
Dim strSelect_Yrs

strSelect_Years = "<option selected value='0'>0.0</option>"
& vbCrlf & "<option value=''>-</option>"
& vbCrlf & "<option value='0.5'>0.5</option>"
& vbCrlf & "<option value='1.0'>1.0</option>"
& vbCrlf & "<option value='1.5'>1.5</option>"
%>

(P.S., do we use line continuation characters in ASP as in VB or no?...)

and then just call that variable in the HTML like so:

<select name="PackageYrs1" class="rating" style="width:43px" id="PackageYrs1" onFocus="playClick();" onChange="playClick();this.size=1;this.style.background='none';" tabindex=302>
<%
  Response.Write strSelect_Years
%>

Is that about right?
0
 
MitchellVIIAuthor Commented:
glennonr:

Interesting - never seen that before, but then again, that wouldn't be surprising in my case :)

Let me test it and see if it works.
0
 
MitchellVIIAuthor Commented:
glennonr:

I just tried that out.  Works great!  I like that better actually because it keeps my ASP smaller and I can also modify those lists more easily.

Coolness!

Mitchell
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now