Using the States Example how can I set Selected to Maryland Without RowNumber

Let's use the states example for the sake of everyone having
the code in front of them. If I am returning a value from the
database that I am writting out to the application like this
<%out.write("STATE_NAME"); %>
how can I set the selected value to that without knowing what
the row number is, here is my try but I get a few error messages:
<option spry:if="{name} == '<%out.write("STATE_NAME");
%>'" value="{name}" selected
="selected">{name}</option>
<option spry:if="{name} != '<%out.write("STATE_NAME");
%>'" value="{name}" >{name}</option>
I get double the states and the following in the debug box:
Caught exception in Spry.Data.Region.prototype.processTokens
while evaluating: Alabama == Exception:[object Error]
Caught exception in Spry.Data.Region.prototype.processTokens
while evaluating: Alabama != '' Exception:[object Error]
This goes on for as many records as I have in the DB,
Please let me know how it could be done if it could be done?

I believe what you guys are looking for is the
Set
Default Row Based on Specific Column sample that is on the
Spry
Samples Page.
The problem of using a spry:if="{name} ..." approach is that
it only makes sure the form select widget is set to what the server
thinks is the current row in the data set, but it doesn't actually
set the current row in the data set to reflect this, so the cities
select is out of sync cause it is defaulting to displaying the
cities for the first row in the states data set.
Checkout the sample I mentioned above, it will show you how
to set up an observer where you can query for the correct row
immediately after the data is loaded, and then set the current row
so that everything is as expected.
--== Kin ==--

Similar Messages

Maybe you are looking for