help with request.form

Results 1 to 2 of 2

Thread: help with request.form

  1. #1
    Join Date
    Dec 1969
    Posts
    940

    Default help with request.form

    Ok. Here goes. I have a form on which there is a selection list of names, the names have numerical values in the selection list. Like this:<BR><BR>&#060;select size="5" name="test" multiple&#062;<BR>&#060;option value="1"&#062;Name1&#060;/option&#062;<BR>&#060;option value="2"&#062;Name2&#060;/option&#062;<BR>&#060;option value="3"&#062;Name3&#060;/option&#062;<BR>&#060;option value="4"&#062;Name4&#060;/option&#062;<BR>&#060;option value="5"&#062;Name5&#060;/option&#062;<BR>&#060;/select&#062;<BR><BR><BR>This is a multipick selection list. My problem is this. When someone selects more than one name the result of request.form("test") is a comma delimited list. Like this: 1,2,3,4 I need to insert into the database one record for each item selected. So if they select name1, and name2, and name3 then I will need to insert three times. My problem is that I don&#039t know how to handle this. The values are not always going to be only one digit long. They can be upto 7 or so. Please provide some help, and code that will help me with this one. Thanks,<BR><BR>Eric

  2. #2
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: help with request.form

    There is a function called split that takes a delimited string and returns a one dimensional array containing the elements.<BR><BR>So, we&#039ll do that.<BR><BR>&#039The string from the select box<BR>Dim strOptions<BR>strOptions = Request("test")<BR><BR>if strOptions = "" then<BR>&#039They selected no options, do nothing<BR>else<BR><BR>Dim myArray<BR>myArray = split(strOptions,",")<BR><BR>&#039Now, loop through the array<BR>Dim iLoop<BR>For iLoop = LBound(myArray) to UBound(myArray)<BR><BR>&#039Do insert here... you can access the number of the current option by: myArray(iLoop)<BR><BR>Next<BR><BR>End If<BR><BR><BR>Hope this helps! I highly recommend you check out:<BR><BR>Technical Definition of the split function<BR>http://help.activeserverpages.com/iishelp/VBScript/htm/vbs195.htm<BR><BR>LBound Def.<BR>http://help.activeserverpages.com/iishelp/VBScript/htm/vbs143.htm<BR><BR>UBound def:<BR>http://help.activeserverpages.com/iishelp/VBScript/htm/vbs212.htm<BR><BR>An article on split: Parsing with Join and Split<BR>http://www.4guysfromrolla.com/webtech/050999-1.shtml

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •