...

View Full Version : Dynamic Form Build - Select Field



JoeP
02-06-2003, 02:41 AM
Does Anyone Have An Alternative To This Code To Optimize It.

I Am Creating A Dynamic Form Based On Some Preliminary Information Captured. I Am Writing Select Fields Based On A Predetermined Option Selected. In This Example The Variable Passed Is "DegreeOfDifficulty" Which May Be 0-5. When I Create The Dynamic Form, I Want The Select Field To Reflect The Predetermined "DegreeOfDifficulty" As The Selected Value. In The Event Of The "0" Value, The Default Case Else Kicks In.

The Code Below Works; However, I Have Other Fields That Have A High Number Of Selections, And This Code Seems Redundant.

I Am Thinking An Array And A Loop Of Somekind Will Be More Efficent, But I Am Not At A Level To Write That! :-(

Any Suggestions Or Direction Would Be Appreciated. TIA




With Response
.write( "<select size='1' name='DegreeOfDifficulty' style='font-family: Arial Narrow; font-size: 10pt'>" )
Select Case DegreeOfDifficulty
Case 1
.write( "<option value='0'>Select Level</option>" )
.write( "<option selected value='1'>Beginner</option>" )
.write( "<option value='2'>Junior</option>" )
.write( "<option value='3'>Intermediate</option>" )
.write( "<option value='4'>Advanced</option>" )
.write( "<option value='5'>Expert</option>" )
Case 2
.write( "<option value='0'>Select Level</option>" )
.write( "<option value='1'>Beginner</option>" )
.write( "<option selected value='2'>Junior</option>" )
.write( "<option value='3'>Intermediate</option>" )
.write( "<option value='4'>Advanced</option>" )
.write( "<option value='5'>Expert</option>" )
Case 3
.write( "<option value='0'>Select Level</option>" )
.write( "<option value='1'>Beginner</option>" )
.write( "<option value='2'>Junior</option>" )
.write( "<option selected value='3'>Intermediate</option>" )
.write( "<option value='4'>Advanced</option>" )
.write( "<option value='5'>Expert</option>" )
Case 4
.write( "<option value='0'>Select Level</option>" )
.write( "<option value='1'>Beginner</option>" )
.write( "<option value='2'>Junior</option>" )
.write( "<option value='3'>Intermediate</option>" )
.write( "<option selected value='4'>Advanced</option>" )
.write( "<option value='5'>Expert</option>" )
Case 5
.write( "<option value='0'>Select Level</option>" )
.write( "<option value='1'>Beginner</option>" )
.write( "<option value='2'>Junior</option>" )
.write( "<option value='3'>Intermediate</option>" )
.write( "<option value='4'>Advanced</option>" )
.write( "<option selected value='5'>Expert</option>" )
Case Else
.write( "<option selected value='0'>Select Level</option>" )
.write( "<option value='1'>Beginner</option>" )
.write( "<option value='2'>Junior</option>" )
.write( "<option value='3'>Intermediate</option>" )
.write( "<option value='4'>Advanced</option>" )
.write( "<option value='5'>Expert</option>" )
End Select
.write( "</select>" )
End With

BigDaddy
02-06-2003, 05:36 AM
Here's a simple dynamic select box. See the attached txt file. Each line of it checks the value of "DegreeOfDifficulty" writes "selected" if the value of the variable matches that of the row of the select box.

By the way, don't know if you realize, but the style:

with response
.write
.write
.write


is actually slower. Chances are, you probably aren't writing anything so complex that causes major performance loss, but it is a bit slower than response.write on every line, or even just putting <% %> tags in your html, as I did here.

JoeP
02-06-2003, 02:06 PM
Thank You! Not only for the code, but the tip on .write!
Your Coding handle will reside as a credit in my code.

BigDaddy
02-06-2003, 06:01 PM
No problem. Glad to help. :)

Like I said, the .write thing probably isn't something that would have caused a major performance hit, but I read an interesting article on it a few months back. whammy gave me the link to it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum