Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retain option group and textarea values 1

Status
Not open for further replies.

richey1

Technical User
Oct 5, 2004
184
GB
Hi

I've got my asp page setup, if the user clicks submits (or refreshes the page) then the input type="text" retains the value on screen as so for example
<INPUT id="Postcode" name="Postcode" size="20" value=" & Postcode & " />

can't do the same for textareas and option groups though ?

tried for option group (doessn't work)

<SELECT id="cat" name="cat" SIZE="7" value=" & cat & " MULTIPLE>

also for textarea, for example (doesn't work also)

<TEXTAREA id="BusinessDescription" name="BusinessDescription" ROWS="2" COLS="32" value=" & BusinessDescription & ">

can't use javascript re. accessibility

any ideas much appreciated
thanks
ian
 
i think I've sorted textarea using (I have to build up my body as a string by the way)

b = b & "<TD colspan=""2""><TEXTAREA id=""BusinessDescription"" name=""BusinessDescription"" ROWS=""2"" COLS=""32"">" & BusinessDescription & "</TEXTAREA> </TD>"
 
sorted option groups too !
using

b = b & "<option value=""Gen""
if condition then
b = b & " selected >Gen</option>"
else
b = b & ">Gen</option>"
end if

etc etc

 
spoke to soon !

how do i implement it now I'm reading from a recordset ?

b = b & "<TR>"
b = b & "<td><label for=""cat"">Business Type (*)</label></td>"
b = b & "<TD colspan=""2"" >Hold down the Ctrl key to select more than one type."
b = b & "<SELECT id=""cat"" name=""cat"" SIZE=""7"" MULTIPLE>"
b = b & "<optgroup label=""Business Categories"">"
do while not objRS2.eof
b = b & "<OPTION value=" & objRS2("Col001") & ">" & objRS2("Col001") & "</OPTION>"
objRS2.movenext
Loop
objRS2.close
b = b & "</OPTGROUP>"
b = b & "</SELECT>"
b = b & "</TD>"
b = b & "</TR>"

thanks !
 
I tried this but no joy

b = b & "<TR>"
b = b & "<td><label for=""cat"">Business Type (*)</label></td>"
b = b & "<TD colspan=""2"" >Hold down the Ctrl key to select more than one type."
b = b & "<SELECT id=""cat"" name=""cat"" SIZE=""7"" MULTIPLE>"
b = b & "<optgroup label=""Business Categories"">"
do while not objRS2.eof
if objRS2("Col001") = request.form("Cat") then
b = b & "<OPTION selected value=" & objRS2("Col001") & ">" & objRS2("Col001") & "</OPTION>"
else
b = b & "<OPTION value=" & objRS2("Col001") & ">" & objRS2("Col001") & "</OPTION>"
end if
objRS2.movenext
Loop
objRS2.close
b = b & "</OPTGROUP>"
b = b & "</SELECT>"
b = b & "</TD>"
b = b & "</TR>
 
You're missing the quotes around your values:
Code:
b = b & "<OPTION selected value=[red]""[/red]" & objRS2("Col001") & "[red]""[/red]>" & objRS2("Col001") & "</OPTION>"
else
b = b & "<OPTION value=[red]""[/red]" & objRS2("Col001") & "[red]""[/red]>" & objRS2("Col001") & "</OPTION>"

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
silly me !

thanks tracy - although it only keeps one value not if multiple ones selected ? but its better than nothing !

ian
 
We've all made that mistake at one time or another. That's why it was so easy to spot.

There should be a way to keep all of the values selected too. What does your request.Form("Cat") look like? I've never used a multiple select. How are the multiple values passed from the form to your program?


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
sorry for the delay in replying. I've been off.
The values are passed comma seperated , that is the way the multiple select works as opposed me doing anything.

The other thing I need to determine is how to retrieve the values if the user decides to edit a record ?
they may have selected one or several (comma seperated) which I'd like to appear in the listbox
I would be happy to just have a print saying you have already select these categories, select anymore and somehow build up a string to update the database with any additions

any help appreciated
thanks
ian
 
i can actually retrieve my values now using.............

b = b & "<TR>"
b = b & "<td><label for=""cat"">Business Type (*)</label></td>"
b = b & "<TD colspan=""2"" >Hold down the Ctrl key to select more than one type."
b = b & "<SELECT id=""cat"" name=""cat"" SIZE=""7"" value = """ & objRS("Cat") & """ MULTIPLE>"
b = b & "<optgroup label=""Business Categories"">"

Dim arrValues, j
arrValues = split(objRS("Cat"), ",")
For j = 0 to UBound(arrValues)
b = b & "" & arrValues(j) & ""
b = b & "<OPTION selected value=""" & arrvalues(j) & """>" & arrvalues(j) & "</OPTION>"
Next

b = b & "</OPTGROUP>"
b = b & "</SELECT>"
b = b & "</TD>"
b = b & "</TR>"


however that only shows the values retrieved, I still need to show all values incase they want to add ! as i did (on the inpit page) using

b = b & "<TR>"
b = b & "<td><label for=""cat"">Business Type (*)</label></td>"
b = b & "<TD colspan=""2"" >Hold down the Ctrl key to select more than one type."
b = b & "<SELECT id=""cat"" name=""cat"" SIZE=""7"" MULTIPLE>"
b = b & "<optgroup label=""Business Categories"">"
do while not objRS2.eof
if objRS2("Col001").value = request.form("Cat") then
b = b & "<OPTION selected value=""" & objRS2("Col001") & """>" & objRS2("Col001") & "</OPTION>"
else
b = b & "<OPTION value=""" & objRS2("Col001") & """>" & objRS2("Col001") & "</OPTION>"
end if
objRS2.movenext
Loop
objRS2.close
b = b & "</OPTGROUP>"
b = b & "</SELECT>"
b = b & "</TD>"
b = b & "</TR>"


thanks
 
If you've got a comma-delimited string, you're in luck. You can use split to turn the string into an array of options, then loop thru the array to set the selected values of the select list.
Code:
aValues = split(request.Form("optList"),",")
for x = 0 to uBound(aValues)
 'do something here with aValues(x)
next


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
thanks tracy

I suppose i could do this........

Dim arrValues, j
arrValues = split(objRS("Cat"), ",")
For j = 0 to UBound(arrValues)
b = b & "" & arrValues(j) & ""
b = b & "<OPTION selected value=""" & arrvalues(j) & """>" & arrvalues(j) & "</OPTION>"
Next
do while not objRS2.eof
b = b & "<OPTION value=""" & objRS2("Col001") & """>" & objRS2("Col001") & "</OPTION>"
objRS2.movenext
Loop

which shows the values they have selected at the top and all other entries (duplicating those selected but does it really matter ?) beneath
 
It may seem a little inefficient, but what I would do is loop thru the array of selected values for each item I was about to add to the select list:
Code:
Dim arrValues, j
arrValues = split(objRS("Cat"), ",")
do while not objRS2.eof
  for j = 0 to UBound(arrValues)
    if arrValues(j) = objRS2("Col001") then
      b = b & "<OPTION selected value=""" & objRS2("Col001") & """>" & objRS2("Col001") & "</OPTION>"
      exit for
    end if
  next
  if j > UBound(arrValues) then
    b = b & "<OPTION value=""" & objRS2("Col001") & """>" & objRS2("Col001") & "</OPTION>"
  end if
  objRS2.movenext
Loop

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
thanks tracy

that only displays the first entry...............

i changed

b = b & "<OPTION selected value=""" & objRS2("Col001") & """>" & objRS2("Col001") & "</OPTION>"

to

b = b & "<OPTION selected value=""" & objRS("Cat") & """>" & objRS("Cat") & "</OPTION>"

and that showed the entries as one value on one line, comma seperated (as you would expect i guess) but no duplicates !

thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top