Click to See Complete Forum and Search --> : Dropdown - Maintaining state on edit form not working


rtown
08-24-2010, 12:06 PM
Hey guys,
I have a form where the user edits a record. The form consists of a dropdown where the field [status] is changed.

The problem is, the dropdown initial value always just goes to the first value in the list, rather than the actual record value. I have tried the following code but I cant get to work:

<select name="Status">
<option value="Not Started" <% if status = "Not Started" then response.write("selected") end if %>>Not Started</option>
<option value="Bill" <% if status = "Bill" then response.write("selected") end if %>>Bill</option>
<option value="Bob" <% if status = "Bob" then response.write("selected") end if %>>Bob</option>
<option value="Joe" <% if status = "Joe" then response.write("selected") end if %>>Joe</option>
</select>

The status is being passed to this page just fine, as the following write the field status successfully:
<%
status = Recordset("Status")
Response.Write status
%>

So whats the deal... Status is recognized and is returning the correct value... yet it will not work to maintain the dropdown value... so right now, the user editing doesnt realize the dropdown is simply reverting back to the first value, and presses save, effectively erasing the previous status... not good. :(

drudeken
08-24-2010, 12:15 PM
Is the "selected" in the correct list item in the outputted source?

rtown
08-24-2010, 12:17 PM
Is the "selected" in the correct list item in the outputted source?

The dropdown on form load just shows "Not Started.. which is the first value in the dropdown. The correct status is "Bill"

And <%status = Recordset("Status")
Response.Write status%> confirms this.

Is that your question? Sorry you may need to clarify, I am somewhat new to asp. :o

drudeken
08-24-2010, 12:23 PM
<select name="Status">
<option value="Not Started" <% if status = "Not Started" then response.write("selected") end if %>>Not Started</option>
<option value="Bill" <% if status = "Bill" then response.write("selected") end if %>>Bill</option>
<option value="Bob" <% if status = "Bob" then response.write("selected") end if %>>Bob</option>
<option value="Joe" <% if status = "Joe" then response.write("selected") end if %>>Joe</option>
</select>

Should it be == instead of =?

<select name="Status">
<option value="Not Started" <% if status == "Not Started" then response.write("selected") end if %>>Not Started</option>
<option value="Bill" <% if status == "Bill" then response.write("selected") end if %>>Bill</option>
<option value="Bob" <% if status == "Bob" then response.write("selected") end if %>>Bob</option>
<option value="Joe" <% if status == "Joe" then response.write("selected") end if %>>Joe</option>
</select>

rtown
08-24-2010, 12:26 PM
Ok, I have confirmed there are odd characters in the string which is why the status is not being matched.. I just dont know how to fix it.. anyone?

This confirms there are odd characters in "Bill" :confused:
<%
status = Recordset("Status")
If Left(status, 4) = "Bill" Then
Response.Write "It's Bill"
Else
Response.Write "There are odd characters in the string"
End if
%>

rtown
08-24-2010, 12:34 PM
Problem solved, for anyone interested we just used a Trim on the status to clear any strange characters... who know what was being added:

<option value="Bill" <% if Trim(status) = "Bill" then response.write("selected") end if %>>Bill</option>

Thanks for the ideas!

drudeken
08-24-2010, 12:35 PM
What odd characters?


try this.


<%
status = Recordset("Status")
If status.Trim().ToLower() = "bill" Then
Response.Write "It's Bill"
Else
Response.Write "There are odd characters in the string"
End if
%>

rtown
08-24-2010, 12:39 PM
^ The above just gives me:

Microsoft VBScript runtime error '800a01a8'

Object required: 'Deb '

drudeken
08-24-2010, 12:41 PM
Forgive my rusty VB. :D I'm in a tomb of C# lately.

rtown
08-24-2010, 12:50 PM
Forgive my rusty VB. :D I'm in a tomb of C# lately.

Haha, no worries. Im just glad it works, whatever it was will remain a mystery. :cool:

drudeken
08-24-2010, 12:51 PM
If you find out what the characters are, and why they were added, I would like to know. This one intrigued me.

rtown
08-24-2010, 12:54 PM
If you find out what the characters are, and why they were added, I would like to know. This one intrigued me.

All trim removes apparently is spaces, so it must be a space. Ill probably never know how though. My modify.asp page, which handles the form has a trim in place for the posted values... so in theory no spaces should exist when the form data gets entered into the DB.
:confused::confused: Haha...

drudeken
08-24-2010, 12:57 PM
Atlease in C#, String.Trim() will trim leading and trailing white space, including line breaks ("\r","\n"). Not sure why either would be there, but good to know if I ever run into it.