Home >Backend Development >PHP Tutorial >PHP ci code to obtain the values ​​of multiple input elements with the same name in the form_php tips

PHP ci code to obtain the values ​​of multiple input elements with the same name in the form_php tips

WBOY
WBOYOriginal
2016-05-16 19:55:381254browse

Sometimes the front page needs to allow the dynamic addition/deletion of multiple values ​​​​of a certain attribute, such as adding books to the bookshelf, and the ability to dynamically add or delete books. There will be multiple input elements in the form on the front page, as follows:

Copy code The code is as follows:

adc4f4ffd1ab63b129c4389d2fd57947
a425711d2b8dfbdda1d02764938653e4
a425711d2b8dfbdda1d02764938653e4
a425711d2b8dfbdda1d02764938653e4
df0c685338bf2429180fb3e4350912bc
f5a47148e367a6035fd7a2faa965022e

When the a.php page receives the form data, you can use $books = $_REQUEST['books']; to get an array of all book titles.
The method of obtaining data through post in PHP CI: $books = $this->input->post('books');//Note that this is books, and the form name is books in the form of an array[]

js gets the values ​​of multiple input boxes with the same name

var els =document.getElementsByName("books");
for (var i = 0, j = els.length; i < j; i++){
alert(els[i].value);
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn