2016-03-05 77 views
0

你好任何一個可以幫助我即時無法隱藏第二個或任何其他按鈕while循環每當文本框的值小於5然後按鈕btn_cart應該禁用bt它不會發生只能在while循環中禁用第一個按鈕如果我將任何其他文本框的值更改爲小於5 bt我的第一個按鈕獲取禁用不others.please幫我我卡住無法禁用第二個按鈕或任何其他按鈕時,點擊

function toggle(element) { 

    if (element.value>'5') { 
     document.getElementById('btn_cart').style.visibility='visible'; 

    } 
    else { 
     document.getElementById('btn_cart').style.visibility='hidden'; 
     alert('Please have Minimum 5 Quantity ') 
    } 
} 



<?php include ('dbconnect.php'); 
    $prodetails = mysql_query("Select * from product where category_id='$product_id' ORDER BY product_craetedate DESC "); 
    while ($fetchprodata = mysql_fetch_array($prodetails)) 
     { 
?> 
<input type="number" class="item_quantity" value="5" id="" onChange="toggle(this)" /> 
<?php echo "<input type='button' class='item_add items' name='btn_cart' id='btn_cart' value='ADD'>" ?> 

<?php } ?> 
+0

提供足夠的細節 –

+0

變化'element.value>'5''到'element.value> 5' – shu

+0

喜我的javascript工作我我想禁用它,只要小於5該按鈕應該被禁用bt它正在經過while循環,所以只有第一個按鈕被禁用nt另一個按鈕被禁用becoz它在while循環中,所以請檢查n幫助 –

回答

0

你已經給每個<input type="button".......> 相同的ID,所以當你做document.getElementById('btn_cart').style.visibility='visible'; 它只會隱藏第一個按鈕。

<?php include ('dbconnect.php'); 
$prodetails = mysql_query("Select * from product where category_id='$product_id' ORDER BY product_craetedate DESC "); 
$i = 1 
while ($fetchprodata = mysql_fetch_array($prodetails)) 
    { 

?> 
<input type="number" class="item_quantity" value="5" id="<?php echo $i?>"  onChange="toggle(this)" /> 
<?php echo "<input type='button' class='item_add items' name='btn_cart' id='btn_cart".$i."' value='ADD'>" ?> 

<?php 
$i++; 
} ?> 

在腳本變化

function toggle(element) { 

if (element.value<'5') { 
    document.getElementById('btn_cart'+element.id).style.visibility='hidden'; 
    alert('Please have Minimum 5 Quantity ') 

    }  
} 
+0

謝謝你這麼多的工作 –

+0

@Javed siddique它的答案是正確的,你可以接受答案,並upvote它。 –

0

變化element.value> '5' 至element.value> 5

+0

看到我的代碼我的JavaScript是問題是我想禁用按鈕btn_cart當的值小於5 ..主要問題是while循環它創建btn根據當im讓數值小於5的任何其他文本框時,獲取數據bt btn_Cart首先將另一個禁用nt。 –

相關問題