Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-06-2003, 01:41 AM   PM User | #1
JoeP
Regular Coder

 
Join Date: Jun 2002
Location: Plano, Texas
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts
JoeP is an unknown quantity at this point
Dynamic Form Build - Select Field

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


Code:
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
JoeP is offline   Reply With Quote
Old 02-06-2003, 04:36 AM   PM User | #2
BigDaddy
Regular Coder

 
Join Date: Sep 2002
Location: Bugaha, NE
Posts: 330
Thanks: 0
Thanked 0 Times in 0 Posts
BigDaddy is an unknown quantity at this point
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.
Attached Files
File Type: txt dropdown.txt (747 Bytes, 169 views)
BigDaddy is offline   Reply With Quote
Old 02-06-2003, 01:06 PM   PM User | #3
JoeP
Regular Coder

 
Join Date: Jun 2002
Location: Plano, Texas
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts
JoeP is an unknown quantity at this point
Thank You! Not only for the code, but the tip on .write!
Your Coding handle will reside as a credit in my code.
JoeP is offline   Reply With Quote
Old 02-06-2003, 05:01 PM   PM User | #4
BigDaddy
Regular Coder

 
Join Date: Sep 2002
Location: Bugaha, NE
Posts: 330
Thanks: 0
Thanked 0 Times in 0 Posts
BigDaddy is an unknown quantity at this point
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.
BigDaddy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:20 PM.


Advertisement
Log in to turn off these ads.