首页 \ 问答 \ 数据库值为html选择下拉列表中的“已选择”项(Database value as “selected” item in html select dropdown list)

数据库值为html选择下拉列表中的“已选择”项(Database value as “selected” item in html select dropdown list)

在我的数据库中添加新记录时,我使用html选择下拉列表将用户对特定字段的选择限制为:新建,良好,公平和差。 这四个值中的一个将始终存储在该字段中。

在另一个页面上,我为用户提供了编辑该字段内容的机会。 在那里,我还将使用相同的html选择下拉列表将用户的选择限制为相同的四个值。

为了将当前值保持为默认值,我需要将其作为下拉列表中的“选定”值。 如何强制数据库中的当前值成为下拉列表中的“选定”值? 谢谢!


When adding a new record to my database I use an html select dropdown list to limit the user's choices for a particular field to: New, Good, Fair and Poor. One of these four values will always get stored in that field.

On another page I give the user a chance to edit the content of that field. There, I will also limit the user's choices to the same four values using the same html select dropdown list.

In order to maintain the current value as the default, I need it to be the "selected" value in my dropdown list. How can I force the current value in the database to be the "selected" value in my dropdown list? Thank you!


原文:https://stackoverflow.com/questions/27366374
更新时间:2023-04-12 06:04

最满意答案

我认为迄今为止的答案是不正确的。 起作用的是像a *= b这样的复合表达式的评估。 总之, 左边的值是在右边之前计算的 。 来自JLS (强调我的):

在运行时,表达式以两种方式之一进行评估。

如果左边的操作数表达式不是数组访问表达式,则:

首先,评估左手操作数以产生变量。 如果此评估突然完成,则由于相同的原因,分配表达式会突然完成; 右侧的操作数不会被评估,也不会进行分配。

否则, 保存左侧操作数的值,然后评估右侧操作数 。 如果此评估突然完成,则由于同样的原因,分配表达式会突然完成,并且不会进行分配。

否则,左侧变量的保存值和右侧操作数的值将用于执行复合赋值运算符指示的二进制运算。 如果此操作突然完成,则由于同样的原因,赋值表达式会突然完成并且不会发生分配。

否则,二进制运算的结果将转换为左侧变量的类型,并经过值集转换(第5.1.13节)到适当的标准值集(不是扩展指数值集),结果的转换被存储到变量中。

在你的例子中:

a[0] *= a[0] = b[n    ];
  1. 计算a[0]值并存储在tmp
  2. 评估a[0] = b[n] ,给出b[n]的值(并且将a[0]的值改为b[n]
  3. tmp * a[0]
  4. 最后一步的结果被分配给a[0]

所以,你得到的是有效a[0] *= b[n]

编辑:关于从左到右评估分配的困惑:我没有发现在JLS中使用的术语,恕我直言,这是不正确的(尽管它在Java教程中使用)。 它被称为正确的 - **联想*屁股JLS这样说关于任务:

有12个分配操作员; 所有都是从句法上右联合的(他们从右到左分组)。 因此,a = b = c意味着a =(b = c),它将c的值赋给b,然后将b的值赋给a。


I think the answers so far are not correct. What comes into play is the evaluation of compound expressions like a *= b. In short, the value of the left hand side is computed before the right hand side. From the JLS (emphasis mine):

At run time, the expression is evaluated in one of two ways.

If the left-hand operand expression is not an array access expression, then:

First, the left-hand operand is evaluated to produce a variable. If this evaluation completes abruptly, then the assignment expression completes abruptly for the same reason; the right-hand operand is not evaluated and no assignment occurs.

Otherwise, the value of the left-hand operand is saved and then the right-hand operand is evaluated. If this evaluation completes abruptly, then the assignment expression completes abruptly for the same reason and no assignment occurs.

Otherwise, the saved value of the left-hand variable and the value of the right-hand operand are used to perform the binary operation indicated by the compound assignment operator. If this operation completes abruptly, then the assignment expression completes abruptly for the same reason and no assignment occurs.

Otherwise, the result of the binary operation is converted to the type of the left-hand variable, subjected to value set conversion (§5.1.13) to the appropriate standard value set (not an extended-exponent value set), and the result of the conversion is stored into the variable.

In your example:

a[0] *= a[0] = b[n    ];
  1. value of a[0] is computed and stored in say tmp
  2. a[0] = b[n] is evaluated, giving the value of b[n] (and changing the value of a[0] to b[n])
  3. tmp * a[0] is computed
  4. the result of the last step is assigned to a[0]

So, what you get is effectively a[0] *= b[n].

EDIT: About the confusion about right-to-left-evaluation of assignments: I did not find that terminology used in the JLS, and IMHO it is not correct (although it is used in the Java tutorials). It is called right-**associative* assThe JLS says this about assignments:

There are 12 assignment operators; all are syntactically right-associative (they group right-to-left). Thus, a=b=c means a=(b=c), which assigns the value of c to b and then assigns the value of b to a.

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)