2016-03-05 97 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。 –