简体   繁体   English

将文本框数组值传递到javascript中

[英]pass text box array values into javascript

I have a hidden text-box which is in for loop.(Codeigniter View File) 我在for循环中有一个隐藏的文本框。(Codeigniter查看文件)

<input type="hidden" value="<?php echo $name->file_name;?>" name="high_name[]" />

i want to pass this array values into my java script function. 我想将此数组值传递到我的Java脚本函数中。 I dont know how to do it for array. 我不知道如何为数组做。

$(".button").click( function() {

var name =  document.getElementById('high_name[]').value; 
alert(name);

});

what i want is, get these names and pass it to the another text-area's value. 我想要的是获取这些名称,并将其传递给另一个文本区域的值。

<textarea>.....</textarea>

Something like this? 像这样吗

NOTE : I adjusted the HTML slightly. 注意 :我稍微调整了HTML。 A class was added to the inputs and they were made text in stead of hidden . 在输入中添加了一个类,使它们成为text ,而不是hidden text The text is for example purposes, see what is happening. text仅供参考,请参阅发生的情况。 The class because (as far as i know) not all browsers select elements with a array notation all that good. 该类是因为(据我所知)并非所有浏览器都选择具有数组表示法的元素。

 $(".button").click( function() { $('input.high_name').each(function(){ var currentVal = $("#toHere").val(); $("#toHere").val(currentVal + "\\n" + $(this).val()); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" value="Value1" name="high_name[]" class="high_name" /> <input type="text" value="Value2" name="high_name[]" class="high_name" /> <input type="text" value="Value3" name="high_name[]" class="high_name" /> <button class="button">Click me</button> <textarea id="toHere"></textarea> 

You might want to optimize the \\n part. 您可能需要优化\\n部分。 But that comes when you implement this example to your own needs 但是,当您根据自己的需要实施此示例时

document.getElementById('high_name[]') does not work since high_name[] is not the Id of the HTML element. document.getElementById('high_name[]')无效,因为high_name[]不是HTML元素的ID。 Instead try this 而是试试这个

var name = $('input[name="high_name[]"]').val();
$("#textarea_id").html(name);

//ensure that jQuery is included //确保包含jQuery

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

相关问题 使用javascript将下拉值传递给文本框 - Pass dropdown values to text box with javascript JavaScript-添加文本框值并将其存储在数组中 - JavaScript - Adding text box values an storing it in an array 将文本框值分配给Javascript中的字符串数组? - Assigning Text Box Values to a String Array in Javascript? 如何在javascript变量中传递多个文本框值? - how to pass multiple text box values in javascript variable? 将动态创建的文本框值按顺序存储在 javascript 数组中 - Store dynamically created text box values in an javascript array in an order javascript 文本框数组并获取值并关注特定字段 - javascript text box array and get values and focus on particular field 如何使用javascript将文本框的值传递给禁用的文本框 - How to pass the value of the text box to the disabled text box using javascript 如何通过javascript将值传递到文本框 - How to pass value to text box through javascript 如何将输入文本从数据表插入数据库并乘以2个值,然后将该值传递给Javascript表中的输入框 - How to Insert input text from datatables to database and multiply 2 values, pass that value to input box in table in Javascript 如何将word文档中的值作为输入传递到javascript的文本框并在循环中运行它 - how to pass values from word document as an input to the text box of the javascript and run it over a loop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM