Milena Jażdżyk Milena Jażdżyk - 1 year ago 92
jQuery Question

JQuery get the 9th character in a number

I have to get the 9th character in a barcode (10361510700149) and when this char is equal to 7 it will set my checkbox as "checked".

Don't laugh, I wrote sth but of course it doesn't work. It's my first journey with JQuery :D

[event: , load,
var bar = $(”#barcode”).val();
var bars = bar.toString();
var nine = bars.charAt(8);
var nine_as_number = parseInt(nine);
if (nine_as_number == 7) {
$(’.c1540’).prop(’checked’, true);

Answer Source

Use this code

    if ($(this).text().charAt(8) == 7)
        $(this).siblings("input").attr("checked", true);
<script src=""></script>
    <input type="checkbox" />
    <input type="checkbox" />
    <input type="checkbox" />

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download