jwebster77
asked on
Button to fire javascript only if @Html.EditorFor is equal to "Closed" in MVC
Hello,
I have a save button on the edit page that calls a javascript function when clicked.
How can I make this button call the javascript function only if a dropdown contains the selection "Closed"?
This is the HTML code for the dropdown:
Thank you very much.
I have a save button on the edit page that calls a javascript function when clicked.
<input type="submit" value="Save" class="btn btn-default" name="action" onclick="Confirm()" />
How can I make this button call the javascript function only if a dropdown contains the selection "Closed"?
This is the HTML code for the dropdown:
@Html.LabelFor(model => model.vcStatus, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(
m => m.vcStatus,
Model.StatusList)
@Html.ValidationMessageFor(model => model.vcStatus, "", new { @class = "text-danger" })
</div>
Thank you very much.
What does the rendered html/js look like?
ASKER
Hi, do you mean to see the Javascript code?
function Confirm() {
var input = $("<input />");
input.attr("type", "hidden").attr("name", "confirm_value");
if (confirm("Do you want to save the ticket to the knowledge base archive?")) {
input.val("Yes");
} else {
input.val("No");
}
$("form")[0].appendChild(input[0]);
}
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.