表单提交后保留下拉列表值
我有一个表单,用户对一首诗进行从 1 到 3 的评分。我的代码如下:
<select name="rating">
<cfif len(duplicateCheck.score)><option value="#duplicateCheck.score#">You scored: #duplicateCheck.score#</option>
<cfelse><option value="">– Rate This Poem –</option>
</cfif>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
如果用户已经对这首诗进行了评分,我会尝试选择他们之前的分数。如果没有,用户可以选择1-3。我该怎么做?
I have a form where a user rates a poem from 1 to 3. My code is as follows:
<select name="rating">
<cfif len(duplicateCheck.score)><option value="#duplicateCheck.score#">You scored: #duplicateCheck.score#</option>
<cfelse><option value="">– Rate This Poem –</option>
</cfif>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
If the user has already rated the poem, I am trying to make their previous score be selected. If not, the user can select 1-3. How should I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
取决于您如何存储用户已经对这首诗进行评分的事实。但从高层次来看:
那么,您是否已经掌握了用户是否对这首诗进行了评分?或者这是真正的问题吗?
Depends on how you're storing the fact that the user has already rated the poem. But from a high level:
So, do you already have a handle on whether or not the user has rated the poem? Or is that the actual question?
如果您循环浏览选项列表,您可以动态地执行此操作。
或者您可以移动代码以从选项 html 中选择下拉列表,这是我更喜欢的。
If you loop through your list of options you could do this dynamically.
Or you can move the code to select the drop down out of the option html, which i prefer.