Using a variable in jQuery to perform a function...
Posted
by
DevlshOne
on Stack Overflow
See other posts from Stack Overflow
or by DevlshOne
Published on 2011-01-06T19:37:49Z
Indexed on
2011/01/06
19:53 UTC
Read the original article
Hit count: 512
Can someone tell me what's wrong with this code? It doesn't seem to be recognizing the '#del[' + cid + ']' selector, at all. Which is the exact name of the ID in my PHP code.
$(function() {
var cid = '<?=$row['c_id'];?>';
$('#del[' + cid + ']').click(function() {
alert('clicked!');
var oldqty = <?=$row['qty'];?>;
var qtyID = "'" + '#qty' + cid + "'";
alert(qtyID);
if ($(qtyID).is(':checked')) {
$(this).(function() {
$(this).val(0);
});
};
if($(qtyID).not(':checked')) {
$(this).(function() {
$(this).val(0);
});
};
});
});
Here's the PHP code that implement $row['c_id']:
echo "<input class=\"number aln_center\" type=\"text\" name=\"qty[" . $row['c_id'] . "]\" id=\"qty" . $row['c_id'] . "\" value=\"" . $row['qty'] . "\" size=\"3\" onchange=\"return validateChgMLQty('qty" . $row['c_id'] . "'," . $row['qty'] . ");\" />\n";
echo "<input type=\"hidden\" name=\"telco[" , $row['c_id'] . "]\" id=\"telco" . $row['c_id'] . "\" value=\"" . $row['btelco'] . "\" />\n";
echo "<br />Delete\n";
echo "<input type=\"checkbox\" name=\"del[" . $row['c_id'] . "]\" id=\"del" . $row['c_id'] . "\" />\n";
I'm trying to get the value in the input statement to change to "0" if the "Delete" checkbox is clicked and then return back to it's original contents when unchecked. It never even gets to the first alert box, so it has nothing to do with qtyID and when viewing source, the 'var cid' line is populated with the correct integer passed from PHP variable $row['c_id'].
© Stack Overflow or respective owner