Ignore my novice knowledge in jQuery. I started to learn recently and I have a challenge in front of me. I have a checkbox with names checkbox_0, checkbox_1 and want to remove "checkbox_" from the strings so that I would use the 0, 1 in my loop to extract the data for that index. Thanks
aData value alerts me the value checkbox_0, checkbox_1 etc. those are the checkboxes selected.
submitButton.on("click", function() {
$("Table :checked").each(function(e) {
var iData =Table.fnGetData( this.parentNode);
// Strip of the checkbox_ from the string
for(var i=0; i<=iData.length; i++) {
aData = iData[i][7];
}
alert(aData);
Table.fnDraw();
});
});
This is just a JavaScript, not a jQuery, thing.
To remove the first occurence of the work “checkbox_”:
Or if you know it’ll always be in the form
"checkbox_n"wherenis a digit,…which chops the first nine characters off the string.
In either case, you end up with a string. If you want a number, you can use
parseInt:…or just put a
+in front of it to cause an automatic cast (but note that in that case, both decimal and hex strings will be handled):Note that I’ve written
updatedString = originalString.blah(...);but of course you can replace your reference, e.g., “originalString = originalString.blah(…);`.More to explore:
String