[英]How can I modify my <textarea> html value based on user input
I have a html textarea element in my page where user gives comma separate values.我的页面中有一个 html textarea 元素,用户在其中提供逗号分隔值。 for example below.例如下面。
A-48402,AA,SBAFL,AA+,USD,,
From javascript (which I prefer) I am applying logic to check if the last row value is blank (separated by comma only) then to put a String value 'Y'.从 javascript (我更喜欢)我正在应用逻辑来检查最后一行值是否为空白(仅由逗号分隔)然后放置一个字符串值'Y'。 Thus I am writing the below因此,我正在写以下内容
var data = document.getElementById('txid').value;
rows = data.split('\n');var row1 = rows[0];row1Values=row1 .split(',');
Then I am applying logic to verify whether the last value for every row is blank or not, which is actually blank, then adding the below.然后我应用逻辑来验证每一行的最后一个值是否为空白,实际上是空白,然后添加以下内容。
row_values.push('Y');
It is reflecting in debugger.它反映在调试器中。
But what I see is the value 'Y' in the Java action class is not reflecting and showing usual 'Y' while the page submit.但我看到的是 Java 操作 class 中的值“Y”在页面提交时没有反映和显示通常的“Y”。 How can I add this value 'Y' in every rows end (where there is blank) so that it will be visible in action class?如何在每一行末尾(有空白的地方)添加这个值'Y',以便它在 class 中可见?
String Data = request.getParameter('mbs_inst_data');
This data is populated with the same blank values.该数据填充了相同的空白值。
You can use it like this.你可以像这样使用它。
<p id="demo">Visit Microsoft! ,,</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var str = document.getElementById("demo").innerHTML;
var res = str.replace(/,,$/, ',Y');
document.getElementById("demo").innerHTML = res;
}
</script>
Output Output
Visit Microsoft! ,Y
I guess this would help you.我想这会对你有所帮助。
If you're only checking for the last row then the only case that would happen is when it's,, so you can just do a simple check如果你只检查最后一行,那么唯一会发生的情况是它是,所以你可以做一个简单的检查
let data = 'A-48402,AA,SBAFL,AA+,USD,,'
data = data.split(',')
let lastRowIsBlank = data[data.length-2] === ""
// we are doing length - 2 because in your situation we have 2 ""
// since you have two commas. If you have only 1 comma we would
// the same steps but with length - 1
if(lastRowIsBlank) data[data.length-2] = "Y"
return data.toString()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.