I am trying to wire up a button with some web app using the click method but it's not working. The JS on the rest of my web site is working fine but this does not seem to like me.
I am new to ASP.NET and I am working using a tutorial so if anything is done in a certain way it's because that's how it's done in tutorial. Here is my code of the page that is creating the problem, I will implement the function javascript how calculate montantbrut = courn + courm + cours
Create razor view :
<h2>Create</h2>
<div class="form-horizontal">
<h4>Coordonnee</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.EnseignantId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.EnseignantId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.EnseignantId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Nom, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Nom, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Nom, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Specialite, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.Specialite, new SelectList(ViewBag.list), "إختر إختصاص ",htmlAttributes:new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Specialite, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Rang, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.Rang, new SelectList(ViewBag.list), "إختر رتبة ", htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Rang, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Courn, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Courn, new { htmlAttributes = new { @class = "form-control" },,@id="courn" })
@Html.ValidationMessageFor(model => model.Courn, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Tdn, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Tdn, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Tdn, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Tpn, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Tpn, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Tpn, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Courm, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Courm, new { htmlAttributes = new { @class = "form-control" },@id="courm" })
@Html.ValidationMessageFor(model => model.Courm, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Tdm, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Tdm, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Tdm, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Tpm, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Tpm, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Tpm, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Cours, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Cours, new { htmlAttributes = new { @class = "form-control" } ,,@id="cours"})
@Html.ValidationMessageFor(model => model.Cours, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Tds, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Tds, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Tds, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Tps, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Tps, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Tps, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Montantbrut, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Montantbrut, new { htmlAttributes = new { @class = "form-control" },@id="montanbrut" })
@Html.ValidationMessageFor(model => model.Montantbrut, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Tva, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Tva, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Tva, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Montantnet, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Montantnet, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Montantnet, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-primary" onClick="savebtn" />
</div>
</div>
</div>
And Javascript code :
@section scripts {
<script type="text/javascript">
$(document).ready(function(){
$('courn').change(function () {
$('montantbrut').val = $('courn').val + $('courm').val+ $('cours').val;
alert("test de click");
});
});
</script>
-
Where is JavaScript here? Its simple View page.Sh.Imran– Sh.Imran2020年08月16日 13:38:04 +00:00Commented Aug 16, 2020 at 13:38
-
hi sh.Imran this is code javascripte : @section scripts { <script type="text/javascript"> $(document).ready(function(){ $('msd').change(function () { $('mg').val = $('msu').val + $('msd').val; alert("test de click"); }); }); </script>mohamed– mohamed2020年08月16日 13:42:57 +00:00Commented Aug 16, 2020 at 13:42
-
So put it in your question. You can Edit the question.Sh.Imran– Sh.Imran2020年08月16日 13:44:08 +00:00Commented Aug 16, 2020 at 13:44
-
I edit it , if you have another solution with c# in razor page youn can help me and thnx youmohamed– mohamed2020年08月16日 13:57:42 +00:00Commented Aug 16, 2020 at 13:57
-
Yes check my answer, it would probably work.Sh.Imran– Sh.Imran2020年08月16日 14:07:58 +00:00Commented Aug 16, 2020 at 14:07
2 Answers 2
Here you should use #
with courn
and other id's
as selector in javascript.
$('#courn').change(function () {
var calc = $('#courn').val() + $('#courm').val() + $('#cours').val();
$('#montantbrut').val(calc);
alert("test de click");
});
1 Comment
You don't use the # sign in jquery selector, and jquery don't find the element. In query selectors you need to use # for id and . for class attributes.
The right code is:
@section scripts {
<script type="text/javascript">
$(document).ready(function(){
$('#courn').change(function () {
$('#montantbrut').val($('#courn').val() + $('#courm').val() + $('#cours').val());
alert("test de click");
});
});
</script>