根据html中的复选框选择填充文本框
populating text box based on checkbox selections in html
我正在尝试设置一个html文件,其中我有以下复选框:
()我有一个账单地址:我有一个账号:
网站将有一个大的文本框。在这个文本框中,如果我检查账单地址,我应该有文本"账单地址:"出现在文本框中。如果我还检查了账号"账号:"应该出现在文本框中"账单地址"的下面一行。
我写的代码是基于这个网站上的另一个堆栈溢出查询:
复选框填充表单字段
我如何使用这段代码来获得我上面解释的期望结果?
附件是我目前为止的代码:
<html lang="en" >
<head>
<script src="jStorage/json2.min.js"></script>
<script src="jStorage/jquery-1.12.2.min.js"></script>
<script src="jStorage/jstorage.min.js"></script>
<body>
I have a billing address: <input type="checkbox" id="checkbox1" value='Billing Address: ' />
<br>
I have an account number: <input type="checkbox" id="checkbox2" value='account number:' />
<br>
<font size=2><table border=0 cellspacing=0 cellpadding=0 width=100%><tr>
<td width='40%' valign='center' align='right'>Enter Remarks in free format: </td>
<td align='center' width=5%></td>
<td align='left'>
<td align='left'><textarea id='remarks' rows='10' cols='50'</textarea>
</td>
</tr>
<script>
$(document).ready(function(){
$("#checkbox1").change(function() {
if(this.checked) {
//alert("checked ");
//get the values of the filled fields
$name = $("#checkbox1").val();
$phone = $("#checkbox2").val();
$total = $name+$phone;
//console.log("name");
// then add those values to your billing infor window feilds
$("#remarks").val($total);
//$("#remarks").val($phone);
// then form will be automatically filled ..
}
else{
$('#remarks').val('');
//$("#phone_billing").val('');
}
});
});
</script>
</body>
</html>
你想要这样的东西吗?它将显示(在文本框中)被选中的任何复选框的值。
<html lang="en" >
<body>
I have a billing address: <input type="checkbox" id="checkbox1" value='Billing Address: ' />
<br>
I have an account number: <input type="checkbox" id="checkbox2" value='account number:' />
<br>
<font size=2><table border=0 cellspacing=0 cellpadding=0 width=100%><tr>
<td width='40%' valign='center' align='right'>Enter Remarks in free format: </td>
<td align='center' width=5%></td>
<td align='left'>
<td align='left'>
<textarea id='remarks' rows='10' cols='50'></textarea>
</td>
</tr>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script>
$(document).ready(function(){
$("[type=checkbox]").change(function() {
var msg = "";
$('input:checked').each(function(i,v){
msg += $(v).val() + "'n";
});
$("#remarks").val(msg);
});
});
</script>
</body>
</html>
相关文章:
- 使用JSON文件中的变量(字符串)填充文本区域
- JavaScript在其他页面上用html内容填充文本框
- 如何制作每次填充文本框时都会填充的进度条
- 使用两个下拉列表的值填充文本框
- 编辑后无法用Javascript填充文本框
- HTML5使用Javascript填充文本标记的有效方式
- 填充文本框取决于php中的下拉选择
- html5具有特定alpha的画布填充文本和具有不同alpha的背景
- 如何从选定的组合框中填充文本框
- 点击剑道网格的编辑,在剑道窗口中填充文本框/DDL
- 有没有一种方法可以用包含ENTER键换行符的SQL数据填充文本区域表单
- 从下拉框中获取选定的值,并使用来填充文本框php javascript
- 使用带有数据库信息的下拉菜单填充文本框
- 使用php创建的下拉列表中的选择单独填充文本区域
- 使用JavaScript返回click-li项目的值,并用结果填充文本区域
- 用数字而不是文本填充文本框值
- 使用表单按钮填充文本输入
- 在模式窗口中填充文本区域
- 填充文本不起作用
- 我正在用来自选择的数据填充文本框,它可以工作,但是