Kod
<script type="text/javascript">
// <![CDATA[
$(document).ready(
function() {
$("#dodaj_cene").click(function() {
var new_label = $("<label></label>");
var new_input = $("<input type=\'text\' name=\'cena[]\' />");
var new_link = $("<a></a>");
new_link.attr("href", "#");
new_link.html("usuń");
new_link.click(function() {
$(this).parent("label").remove();
return false;
});
new_label.append(new_input);
new_label.append(new_link);
$("form[name=formularz]").append(new_label);
return false;
});
});
// ]]>
</script>
// <![CDATA[
$(document).ready(
function() {
$("#dodaj_cene").click(function() {
var new_label = $("<label></label>");
var new_input = $("<input type=\'text\' name=\'cena[]\' />");
var new_link = $("<a></a>");
new_link.attr("href", "#");
new_link.html("usuń");
new_link.click(function() {
$(this).parent("label").remove();
return false;
});
new_label.append(new_input);
new_label.append(new_link);
$("form[name=formularz]").append(new_label);
return false;
});
});
// ]]>
</script>
Niestety po kliknięciu na link "Dodaj cenę" nic nie fuka, nic nie buczy.
Pomoże ktoś?
Usprawniłem nieco skrypt odpowiedzialny za dodawanie 2 dynamicznych inputów, ale kilka problemów zaprząta mi głowę. Po pierwsze po kliknięciu na link 'Dodaj cenę rozmiar' pojawiają się co prawda 2 dynamiczne inputy, tyle że pod formularzem (chciałbym aby wyświetlały się pod nazwą produktu). W dodatku trudność stanowi dla mnie usunięcie 2 niepotrzebnych inputów (na razie działa kasowanie tylko jednego inputa z rozmiarem). Nie jestem specjalistą od jQuery, więc proszę o wyrozumiałość i pomoc.
Kod
<script type="text/javascript">
// <![CDATA[
$(document).ready(
function() {
$("#dodaj").click(function() {
var new_label1 = $("<label>Cena: </label>");
var new_label2 = $("<label>Rozmiar: </label>");
var new_input1 = $("<input type=\'text\' name=\'cena[]\' />");
var new_input2 = $("<input type=\'text\' name=\'rozmiar[]\' />");
var new_link = $("<a></a>");
new_link.attr("href", "#");
new_link.html("usuń");
new_link.click(function() {
$(this).parents("label").remove();
return false;
});
new_label1.append(new_input1);
new_label2.append(new_input2);
new_label1.append(new_link);
new_label2.append(new_link);
$("form[name=formularz]").append(new_label1);
$("form[name=formularz]").append(new_label2);
return false;
});
});
// ]]>
</script>
// <![CDATA[
$(document).ready(
function() {
$("#dodaj").click(function() {
var new_label1 = $("<label>Cena: </label>");
var new_label2 = $("<label>Rozmiar: </label>");
var new_input1 = $("<input type=\'text\' name=\'cena[]\' />");
var new_input2 = $("<input type=\'text\' name=\'rozmiar[]\' />");
var new_link = $("<a></a>");
new_link.attr("href", "#");
new_link.html("usuń");
new_link.click(function() {
$(this).parents("label").remove();
return false;
});
new_label1.append(new_input1);
new_label2.append(new_input2);
new_label1.append(new_link);
new_label2.append(new_link);
$("form[name=formularz]").append(new_label1);
$("form[name=formularz]").append(new_label2);
return false;
});
});
// ]]>
</script>
<form name="formularz" class="art_edit" enctype="multipart/form-data" action="?go=towarinsert_" method="post"> <fieldset> <label> <input type="text" name="nazwa" /> </label> <label> </label> '.$checkbox_txt.' <label> </label> <br /> <label> <input type="file" name="fileImage" /> </label> <label> <select name="active" style="width: 200px;"> </select> </label> <br /> <label> <select name="dostepnosc" style="width: 200px;"> </select> </label> <label style="text-align: center;"> <input type="hidden" value="'.$id.'" name="dzial" /> <input style="width: 200px;" type="submit" value="Zapisz" /> </label> </fieldset> </form>