c# - How to disable a submit form button given a certain condition -
i disable cancel button if the record field "status" recorded cancelled. know how disable button problem how jquery know record field "status" cancelled. here codes
@foreach (var rdetail in model.customers.tolist()) { <tr> <td> @html.displayfor(model => rdetail.dateentry) </td> <td> @html.displayfor(model => rdetail.datestart) </td> <td> @html.displayfor(model => rdetail.dateend) </td> <td> @html.displayfor(model => rdetail.status.name) </td> <td> @html.displayfor(model => rdetail.usercode) </td> <td> @html.displayfor(model => rdetail.datemodified) </td> <td> @html.displayfor(model => rdetail.remarks) </td> <td> @html.actionlink("details", "details", "roomreservation", new { id = rdetail.id}, null) | @using (html.beginform("cancelreservation", "rooms", new { roomid = model.id, reservationid = rdetail.id, methodid = 0})) { <input type="submit" value="cancel" class ="cancelsubmit"/> } </td> </tr>
any appreciated, :)
if know status cancelled can disable in razor itself.
<td> @html.actionlink("details", "details", "roomreservation", new { id = rdetail.id}, null); @if(rdetail.status.name.equals("cancelled")) { <input type="submit" value="cancel" class ="cancelsubmit" disabled/> } else { @using (html.beginform("cancelreservation", "rooms", new { roomid = model.id, reservationid = rdetail.id, methodid = 0})) { <input type="submit" value="cancel" class ="cancelsubmit"/> } } </td>
if want jquery way:-
$(function(){ $('.cancelsubmit').each(function(){ if($(this).closest('tr').find('#status_name').text() === 'cancelled') { $(this).prop('disabled',true); } }); });
or inside function :-
$(this).prop('disabled', $(this).closest('tr') .find('#status_name') .text() === 'cancelled');
Comments
Post a Comment