Szukałem szukałem i nie znalazłem. W szystkich postach jest informacja jak dynam
cznie dodać pola, ale wszędzie brak
informacji jak konkretne pola usunąć.
Potrzebuje zrobić coś takiego
DODAJ
|POLE INPUT1| POLE INPUT2| USUŃ
|POLE INPUT1| POLE INPUT2| USUŃ
|POLE INPUT1| POLE INPUT2| USUŃ
Gdzie po naduszeniu na środkowe "usuń" znika wiersz ze strony a pozostałe dwa są nadal.
Znalazłem przykład:
Kod
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="pl-PL">
<head>
<title>Strona z dynamicznym formularzem</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- Nasz kod javascript: -->
<script type="text/javascript">
window.onload = Laduj;
// window.onload = Usun;
function Laduj()
{
document.getElementById('add_input').onclick = DodajElement;
}
function Usun()
{
document.getElementById('add_input').onclick = UsunElement;
}
function DodajElement()
{
var element1 = document.createElement('input');
element1.setAttribute('type', 'text');
var element2 = document.createElement('input');
element2.setAttribute('type', 'text');
var usun = document.createElement('input');
usun.setAttribute('type','submit');
var br =document.createElement('br');
var liczba = 0;
var ilosc = document.forms['add_file'].elements.length;
for (var i = 0; i < ilosc; i++ )
{
if (document.forms['add_file'].elements[i].type == 'text')
{
liczba += 1;
}
}
element1.setAttribute('name', 'text1_'+(liczba+1));
element2.setAttribute('name', 'text2_'+(liczba+1));
usun.setAttribute('name', 'usun-'+(liczba+1));
usun.setAttribute('value', 'usuń');
//element.style.display = "block";
element1.style.margin= "2px";
element2.style.margin= "2px";
//usun.style.display = "block";
usun.style.margin= "2px";
document.forms['add_file'].appendChild(element1);
document.forms['add_file'].appendChild(element2);
document.forms['add_file'].appendChild(usun);
document.forms['add_file'].appendChild(br);
}
function UsunElement() {
if(document.forms[’add_file’].lastChild.type == ‘submit’)
document.forms[’add_file’].removeChild(document.forms[’add_file’].lastChild);
}
</script>
</head>
<body>
<div><a href="#" id="add_input">dodaj nowe pole typu file</a></div>
<form name="add_file" enctype="multipart/form-data" method="post">
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="pl-PL">
<head>
<title>Strona z dynamicznym formularzem</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- Nasz kod javascript: -->
<script type="text/javascript">
window.onload = Laduj;
// window.onload = Usun;
function Laduj()
{
document.getElementById('add_input').onclick = DodajElement;
}
function Usun()
{
document.getElementById('add_input').onclick = UsunElement;
}
function DodajElement()
{
var element1 = document.createElement('input');
element1.setAttribute('type', 'text');
var element2 = document.createElement('input');
element2.setAttribute('type', 'text');
var usun = document.createElement('input');
usun.setAttribute('type','submit');
var br =document.createElement('br');
var liczba = 0;
var ilosc = document.forms['add_file'].elements.length;
for (var i = 0; i < ilosc; i++ )
{
if (document.forms['add_file'].elements[i].type == 'text')
{
liczba += 1;
}
}
element1.setAttribute('name', 'text1_'+(liczba+1));
element2.setAttribute('name', 'text2_'+(liczba+1));
usun.setAttribute('name', 'usun-'+(liczba+1));
usun.setAttribute('value', 'usuń');
//element.style.display = "block";
element1.style.margin= "2px";
element2.style.margin= "2px";
//usun.style.display = "block";
usun.style.margin= "2px";
document.forms['add_file'].appendChild(element1);
document.forms['add_file'].appendChild(element2);
document.forms['add_file'].appendChild(usun);
document.forms['add_file'].appendChild(br);
}
function UsunElement() {
if(document.forms[’add_file’].lastChild.type == ‘submit’)
document.forms[’add_file’].removeChild(document.forms[’add_file’].lastChild);
}
</script>
</head>
<body>
<div><a href="#" id="add_input">dodaj nowe pole typu file</a></div>
<form name="add_file" enctype="multipart/form-data" method="post">
</form>
</body>
</html>
I nie mam pojęcia jak zrobić usuwanie pozycji.