Answer the question
In order to leave comments, you need to log in
Why doesn't js work when pasted into html?
There is such a view with built-in JS
@model Client.Models.Appointment
@{
ViewBag.Title = "Make A Booking";
AjaxOptions ajaxOpts = new AjaxOptions
{
OnSuccess = "processResponse"
};
}
<h4>Book an Appointment</h4>
<link rel="stylesheet" href="~/Content/CustomStyles.css" />
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<script type="text/javascript">
function processResponse(appt) {
$('#successClientName').text(appt.ClientName);
$('#successDate').text(processDate(appt.Date));
switchViews();
}
function processDate(dateString) {
return new Date(parseInt(dateString.substr(6,
dateString.length - 8))).toDateString();
}
function switchViews() {
var hidden = $('.hidden');
var visible = $('.visible');
hidden.removeClass("hidden").addClass("visible");
visible.removeClass("visible").addClass("hidden");
}
$(document).ready(function () {
$('#backButton').click(function (e) {
switchViews();
});
});
</script>
<div id="formDiv" class="visible">
@using (Ajax.BeginForm(ajaxOpts))
{
@Html.ValidationSummary(true)
<p>@Html.ValidationMessageFor(m=>m.ClientName)</p>
<p>Your name: @Html.EditorFor(m => m.ClientName)</p>
<p>@Html.ValidationMessageFor(m => m.Date)</p>
<p>Appointment Date: @Html.EditorFor(m => m.Date)</p>
<p>@Html.ValidationMessageFor(m => m.TermsAccepted)</p>
<p>@Html.EditorFor(m => m.TermsAccepted) I accept the terms & conditions</p>
<input type="submit" value="Make Booking" />
}
</div>
<div id="successDiv" class="hidden">
<h4>Your appointment is confirmed</h4>
<p>Your name is: <b id="successClientName"></b></p>
<p>The date of your appointment is: <b id="successDate"></b></p>
<button id="backButton">Back</button>
</div>
@section scripts {
<script src="~/Scripts/Home/MakeBooking.js" type="text/javascript"></script>
}
Answer the question
In order to leave comments, you need to log in
It turns out that I installed links to old jquery libraries>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question