Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JavaScript] Tworzenie nowych pól formularza i ich pozycjonowanie
Forum PHP.pl > Forum > Przedszkole
pgrzelka
Witam
mam taki kod formularza
Kod
<form id="af" enctype="multipart/form-data" action="" method="post">
<dl class="zend_form">

<dt id="embed-label"><label for="embed" class="required">Kod embed</label></dt>
<dd id="embed-element">
<textarea name="embed" id="embed" rows="4" cols="30"></textarea></dd>

<!-- tu chcę mieć dodatkowe textarea -->

<dt id="submit-label">&nbsp;</dt>
<dd id="submit-element">
<input type="submit" name="submit" id="submit" value="Dodaj Film"></dd>
</dl>

</form>

<span id="add_input">dodaj następną część</span>


i funkcję js dodającą nowe pola textarea
Kod
<script type="text/javascript">

window.onload = Laduj;
var liczba=1;

function Laduj()
{
   var link = document.getElementById('add_input');
   link.onclick = DodajElement;
}

function DodajElement()
{
   var element = document.createElement('textarea');

   liczba ++;
   if (liczba > 15) {
       alert('Możesz dodać maksymalnie 15 części');
       return;
   }
    
   element.setAttribute('name', 'czesci[]');
   element.value= 'kod embed części ' + liczba;
   element.setAttribute('cols', '30');
   element.setAttribute('rows', '4');
//  element.style.display = "block";
   element.style.margin = "0 20px 20px 20px";
   document.forms['af']. appendChild(element);
}
</script>


teraz nowe textarea pojawiają się na samym dole.
jak zrobić aby pojawiały się przed
<dt id="submit-label">&nbsp;</dt>
?
erix
insertBefore winksmiley.jpg
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.