16. marts 2019 - 23:23
Der er
7 kommentarer
Hjælp til at disable checkboxes
Hej, Jeg har følgende kode der finder tidligere datoer i en database: if ($stmt = $conn->prepare("SELECT `id`, `date` FROM `tbl_traeninger` WHERE `date` < CURDATE() AND hold_id = ? ORDER BY date DESC LIMIT 3")) { $stmt->bind_param("i", $hold); $stmt->execute(); $stmt->bind_result($id, $date); while ($stmt->fetch()){ $my_date = array( 'id' => $id, 'date' => date('d-m', strtotime($date)), ); $dates_id[] = $id; $dates[] = $my_date; } # $result->close(); } Disse hentes ud her: $.each(item.workouts, function (index, date) { if(date.status){ tbody += '<td>'; tbody += '<label class="container"><input id="'+date.date_id+'" class="styled" type="checkbox" name="member_'+item.id+'[]" value="'+date.date_id+'" checked><span class="checkmark"></span></label>'; tbody += '</td>'; }else{ tbody += '<td>'; tbody += '<label class="container"><input id="'+date.date_id+'" class="styled" type="checkbox" name="member_'+item.id+'[]" value="'+date.date_id+'"><span class="checkmark"></span></label>'; tbody += '</td>'; } }); Jeg ønsker at checkbox'ene der baseret på tidligere datoerne skal være disabled uanset om de er markeret eller ej. Men jeg kan ikke lige gennemskue hvordan jeg gør det... Er der en der kan hjælpe mig?
Annonceindlæg fra HP
17. marts 2019 - 00:18
#1
Henter du ikke kun dem der gamle med den kode. Det er da det jeg forstår ud fra den sql statement, for så skal du jo bare gør sådan her $.each(item.workouts, function (index, date) { if(date.status){ tbody += '<td>'; tbody += '<label class="container"><input id="'+date.date_id+'" class="styled" type="checkbox" disabled name="member_'+item.id+'[]" value="'+date.date_id+'" checked><span class="checkmark"></span></label>'; tbody += '</td>'; }else{ tbody += '<td>'; tbody += '<label class="container"><input id="'+date.date_id+'" class="styled" type="checkbox" disabled name="member_'+item.id+'[]" value="'+date.date_id+'"><span class="checkmark"></span></label>'; tbody += '</td>'; } });
17. marts 2019 - 00:21
#2
Nej det gør jeg ikke. $dates = array(); if ($stmt = $conn->prepare("SELECT `id`, `date` FROM `tbl_traeninger` WHERE `date` >= CURDATE() AND hold_id = ? ORDER BY date LIMIT 1")) { $stmt->bind_param("i", $hold); $stmt->execute(); $stmt->bind_result($id, $date); while ($stmt->fetch()){ $my_date = array( 'id' => $id, 'date' => date('d-m', strtotime($date)), ); $dates_id[] = $id; $dates[] = $my_date; } # $result->close(); } if ($stmt = $conn->prepare("SELECT `id`, `date` FROM `tbl_traeninger` WHERE `date` < CURDATE() AND hold_id = ? ORDER BY date DESC LIMIT 3")) { $stmt->bind_param("i", $hold); $stmt->execute(); $stmt->bind_result($id, $date); while ($stmt->fetch()){ $my_date = array( 'id' => $id, 'date' => date('d-m', strtotime($date)), ); $dates_id[] = $id; $dates[] = $my_date; } # $result->close(); } }
17. marts 2019 - 00:32
#3
Jeg henter både den kommende dato og de tre seneste datoer samtidig. Disse vises via ovenstående. Så hvis jeg bare vælger "Disabled", så er det alle...
17. marts 2019 - 01:10
#4
prøv det her. har lidt svært ved at se mig ud af hvordan du henter data til dit jquery scritpt var NowDate = new Date(); CheckDate = (NowDate.getDate()) + '-' +((NowDate.getMonth() + 1) < 10 ? '0'+(NowDate.getMonth() + 1) : (NowDate.getMonth() + 1)); $.each(item.workouts, function (index, date) { if(date.status){ tbody += '<td>'; tbody += '<label class="container"><input id="'+date.date_id+'" class="styled" type="checkbox" ' + ((date.dates.date < CheckDate )? 'disabled' : '') + ' name="member_'+item.id+'[]" value="'+date.date_id+'" checked><span class="checkmark"></span></label>'; tbody += '</td>'; }else{ tbody += '<td>'; tbody += '<label class="container"><input id="'+date.date_id+'" class="styled" type="checkbox" ' + ((date.dates.date < CheckDate )? 'disabled' : '') + ' name="member_'+item.id+'[]" value="'+date.date_id+'"><span class="checkmark"></span></label>'; tbody += '</td>'; } });
17. marts 2019 - 01:19
#5
Det virker ikke umiddelbart. Sender lige hele scriptet: <script type="text/javascript"> $(document).ready(function () { $("#createMember").click(function(){ var data = $("#memberForm").serialize(); $.post("savemember.php", {'data': data}, function(){ }); }); $("#save_workouts").click(function(){ var data = $("#myForm").serialize(); $.post("savedata.php", {'data': data}, function(){ }); }); $("#team").change(function () { var team = $("#team").val(); $.get( "json.php", {action: "members", hold: team}, function( data ) { var dates = ''; $.each(data.dates, function (index, item) { dates += '<th class="dynamic_date">' + item.date + '</th>'; }); var tbody = ''; var myVar = 1; $.each(data.members, function (index, item) { tbody += '<tr>'; <?php if (!$mobile) { ?> tbody += '<td style="vertical-align:middle" align="left">' + myVar++ + '</td>'; <?php } else { } ?> tbody += '<td style="vertical-align:middle">' + item.fornavn + ' ' + item.efternavn +'</td>'; tbody += '<td style="vertical-align:middle">' + item.age + ' år</td>'; $.each(item.workouts, function (index, date) { if(date.status){ tbody += '<td>'; tbody += '<label class="container"><input id="'+date.date_id+'" class="styled" type="checkbox" name="member_'+item.id+'[]" value="'+date.date_id+'" checked><span class="checkmark"></span></label>'; tbody += '</td>'; }else{ tbody += '<td>'; tbody += '<label class="container"><input id="'+date.date_id+'" class="styled" type="checkbox" name="member_'+item.id+'[]" value="'+date.date_id+'"><span class="checkmark"></span></label>'; tbody += '</td>'; } }); tbody += '<td></td>'; tbody += '</tr>'; }); $(".dynamic_date").remove(); $(dates).insertBefore("#numbers_of"); $('#myTable tbody').html(tbody); }, 'json'); }); }); </script> $dates = array(); if ($stmt = $conn->prepare("SELECT `id`, `date` FROM `tbl_traeninger` WHERE `date` >= CURDATE() AND hold_id = ? ORDER BY date LIMIT 1")) { $stmt->bind_param("i", $hold); $stmt->execute(); $stmt->bind_result($id, $date); while ($stmt->fetch()){ $my_date = array( 'id' => $id, 'date' => date('d-m', strtotime($date)), ); $dates_id[] = $id; $dates[] = $my_date; } # $result->close(); } if ($mobile) { if ($stmt = $conn->prepare("SELECT `id`, `date` FROM `tbl_traeninger` WHERE `date` < CURDATE() AND hold_id = ? ORDER BY date DESC LIMIT 2")) { $stmt->bind_param("i", $hold); $stmt->execute(); $stmt->bind_result($id, $date); while ($stmt->fetch()){ $my_date = array( 'id' => $id, 'date' => date('d-m', strtotime($date)), ); $dates_id[] = $id; $dates[] = $my_date; } # $result->close(); } } else { if ($stmt = $conn->prepare("SELECT `id`, `date` FROM `tbl_traeninger` WHERE `date` < CURDATE() AND hold_id = ? ORDER BY date DESC LIMIT 3")) { $stmt->bind_param("i", $hold); $stmt->execute(); $stmt->bind_result($id, $date); while ($stmt->fetch()){ $my_date = array( 'id' => $id, 'date' => date('d-m', strtotime($date)), ); $dates_id[] = $id; $dates[] = $my_date; } # $result->close(); } } $today = new DateTime('today'); Koden er rodet, men håber det giver mening? :-/
17. marts 2019 - 01:24
#6
https://ibb.co/4JcF4TK Det er de 3 kolonner til højre jeg gerne vil have "disabled" :-)
17. marts 2019 - 01:44
#7
Har sendt dig en pm
Vi tilbyder markedets bedste kurser inden for webudvikling