我有我的視圖頁面的表單那裏有兩個選擇框和三個輸入框成一排。我把它們放在一個for循環,使五行中的每一行有是二選擇框和3個簡單的文本框中。我在jQuery的寫一個函數,其中,如果我從一個選擇框中選擇值將在一個循環中進行五排後。但出現在第二選擇框,這個函數是在第一隻工作排不是其他四排。我不知道該怎麼做。如果任何一個能爲我的代碼,然後感謝他......遍歷多個文本框代碼點火器PHP
這是我的看法頁
<tr>
<th>Category:</th>
<th>Items:</th>
<th>Selling Price:</th>
<th>quantity:</th>
<th> total:</th>
</tr>
<?php for ($i = 0; $i < 5; $i++) {
?>
<tr>
<td>
<?php echo form_dropdown('cat_id', $records2, '#', 'id="category"');?>
</td>
<td>
<?php echo form_dropdown('item_id', $records3, '#', 'id="items"'); ?>
</td>
<td><?php echo form_input($price); ?> </td>
<td><?php echo form_input($quantity); ?></td>
<td> <?php echo form_input($total); ?>
</td></tr>
<?php }?></table>
我的JavaScript兩個選擇框。
$(document).ready(function(){
$('#check').click(function(){
alert("hello");
return false;
});
$('#category').change(function(){
$("#items > option").remove();
var category_id = $('#category').val();
$.ajax({
type: "POST",
url: "stockInController/get_Items/"+category_id,
success: function(items) //we're calling the response json array 'cities'
{
$.each(items,function(item_id,item_name)
{
var opt = $('<option />');
opt.val(item_id);
opt.text(item_name);
$('#items').append(opt);
});
}
});
});
});
的JavaScript發送值控制器
<script type="text/javascript">
$('#btn').click(function() { // $("#form").serialize()
var cust_id = $('#cust_id').val();
var item_id = $('#items').val();
var sales_date = $('#sales_date').val();
var sales_bill_no = $('#sales_bill_no').val();
var price = $('#price').val();
var quantity = $('#quantity').val();
var form_data = {
cust_id: $('#cust_id').val(),
sales_date: $('#sales_date').val(),
sales_bill_no: $('#sales_bill_no').val(),
price: $('#price').val(),
quantity: $('#quantity').val(),
item_id: $('#items').val(),
};
$.ajax({
url: "<?php echo site_url('salesController/addSales'); ?>",
type: 'POST',
data: form_data,
dataType: 'json',
success: function(msg) {
if(msg.res == 1)
{
$(".success").fadeIn(500).delay(2000).fadeOut(500);
alert("true");
}
else{
alert("false");
}
}
});
return false;
});
</script>
我已經做到了這一點,但是這不工作
<?php echo form_dropdown('cat_id', $records2, '#', "id='category_".$i."'");?>
<?php echo form_dropdown('item_id', $records3, '#', "id='items_".$i."'"); ?>
<script type="text/javascript">// <![CDATA[
$(document).ready(function()
{
for (var i= 0; i<5; i++)
{
$('#category_'+ i).change(function(){
$('#items_'+ i > option").remove();
var category_id = $('#category_'+ i).val();
$.ajax({
type: "POST",
url: "stockInController/get_Items/"+category_id,
success: function(items)
{
$.each(items,function(item_id,item_name)
{
var opt = $('<option />');
opt.val(item_id);
opt.text(item_name);
$('#items_'+ i).append(opt);
});
}
});
});
}
});
1)不要使用諸如「_CODE爲我__「..我們在這裏引導..不是代碼.. –
2)你在所有5行中使用相同的ID ...我的意思是'category'&'我tems' ..所以您的代碼不工作..使用唯一的ID,比如'類別1,category2..category5' –
我怎樣才能給他們一個diffrnt id作爲他們在德路 – user1972143