简体   繁体   English

Javascript /填充表单字段

[英]Javascript/populate form fields

I have a basic HTML form which is a table with four fields on either side. 我有一个基本的HTML表单,该表单是一个在任一侧都有四个字段的表。 Each field has three values: comment, date, sameas 每个字段具有三个值:评论,日期,相同

What I am trying to figure out is getting those "same as" menus to populate data into the corresponding field. 我试图弄清楚的是获得那些“与”相同的菜单,以将数据填充到相应的字段中。 ie: A user enters a date and comment at Right3 and chooses "Same as Left2," the date, comment and sameas values are automatically populated at Left2. 即:用户在Right3输入日期和注释,然后选择“与Left2相同”,日期,注释和sameas值将自动填充到Left2。

I am a novice at javascript, but if someone could push me in the right direction, I'd appreciate it. 我是javascript的新手,但是如果有人可以向正确的方向推我,我将不胜感激。

Edit : I have figured out how to populate the text areas thanks to your code snippets. 编辑 :由于您的代码段,我已经弄清楚了如何填充文本区域。 Here is the result so far 是到目前为止的结果

Can I integrate the other two fields into the same function? 我可以将其他两个字段集成到同一功能中吗?

I would use jQuery to get the value of the select when it changes (using change function ) and then set the value of the fields related to the select to populate the values of the field selected. 我将使用jQuery在更改时获取select的值(使用change function ),然后设置与select相关的字段的值以填充所选字段的值。

It seems complicated but a example should make it easier. 看起来很复杂,但是举个例子可以使事情变得简单。 Of course it's a very small example but I guess you will be able to do what you want with this example. 当然,这是一个很小的示例,但是我想您将可以通过该示例执行所需的操作。

Hope it's a little light you can follow. 希望您可以照着做。 :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM