Ben kullanıcı forma girdi kümesi eklemek için yeteneğine sahip olacak bir dinamik form oluşturma. Html bu gibi görünüyor:
<form>
<input id="title1" class="title" name="title1" type="text" value="">
<input id="productionCompany1" name="productionCompany1" type="text" value="">
<input id="year1" name="year1" type="text" value="">
<input id="role1" name="role1" type="text" value="">
<div id="newCredit"> </div>
<a href="#" id="addCredit">add another credit</a>
</form>
Kullanıcı "addCredit" kimliği ile bağlantısını tıkladığında aşağıdaki jQuery komut dosyası denir:
$(document).ready(function() {
var $ac = $('#addCredit');
$ac.click(function() {
/* the following two lines are where the problem lies? */
var $credInt = $(this).prev(".title");
$.get("addCredit.php", {num: $credInt},
function(data){
$('#newCredit').append(data);});
return false;
});
});
JQuery işlevi bu gibi görünüyor ki, "addCredit.php" adında bir php dosyası sorgular:
<?php
$int = $_GET["num"];
$int = substr($int, -1);
$int++;
?>
<input id="title<?php echo $int;?>" class="title" name="title<?php echo $int;?>" type="text" value="">
<input id="productionCompany<?php echo $int;?>" name="productionCompany<?php echo $int;?>" type="text" value="">
<input id="year<?php echo $int;?>" name="year<?php echo $int;?>" type="text" value="">
<input id="role<?php echo $int;?>" name="role<?php echo $int;?>" type="text" value="">
Benim sorun addCredit.php sayfasına gönderilir ve buna göre form alanları güncelleştirmek böylece düzgün ayarlanmış javascript değişken $ credInt oluyor. Ben de formu eklenir her zaman, gönderilen bir sonraki değeri artırılır değer olduğundan emin olmak gerekir.
Bunu gerçekleştirmek nasıl Herhangi bir düşünce? Yardımınız için teşekkür ederim.