asp.net mvc - Converting an @Html.Textbox button to submit button -
i trying convert @html.textbox
image button submit
button onclick calling javascript function can't seem figure out validation part. believe need submit button.
i trying rid of image keep functionality.
here's what's working today.
@html.textbox("next", null, new {type = "image", src = @url.content("../app_themes/icons/button_next.png"), @class = "imgbottom", onclick = "javascript: validateselection ($(\"[name$='selecteditems']:checked\"))"}) function validateselection(item) { if (item == null || item.length == 0) { var validationsummary = $('.validation-summary-errors ul'); if (validationsummary.length > 0 && $('.validation-summary-errors ul li').length == 0) { validationsummary.append('<li>' + "please select @ least 1 item" + '</li>'); } var errors = $("[name='errormessage']"); if (errors.length > 0) { errors.hide(); } var buttongeneratereport = $("#generatereport"); if (buttongeneratereport.length > 0) { buttongeneratereport.hide(); } event.preventdefault(); }
}
<button type="submit" class="imgbottom" onclick="validateselection('selecteditems');"> <img src="@url.content("~/app_themes/icons/button_next.png")" alt="next" /><br /> next </button>
the "~/"
part of url content string represents project root, adjust fit correct file address later.
or use fontawesome , replace image entirely that. it's size scalable because of css , has simpler syntax.
<button type="submit" class="imgbottom" onclick="validateselection('selecteditems');"> <i class="fa fa-angle-double-right" aria-hidden="true"></i> next </button>
then in jquery function:
function validateselection(elementname){ var selecteditems = $("[name='" + elementname + "']:checked"); if (selecteditems === null || selecteditems.length === 0) { var validationsummary = $('.validation-summary-errors ul'); if (validationsummary.length > 0 && $('.validation-summary-errors ul li').length == 0) { validationsummary.append('<li>' + "please select @ least 1 item" + '</li>'); } var errors = $("[name='errormessage']"); if (errors.length > 0) { errors.hide(); } var buttongeneratereport = $("#generatereport"); if (buttongeneratereport.length > 0) { buttongeneratereport.hide(); } event.preventdefault(); } }
Comments
Post a Comment