-1
Can anyone tell me how to use datepicker onchange event to do a check on selected date?
in my cshtml is like this:
@Html.EditorFor(model => model.Dat_emissao, "{0:dd/MM/yyyy}", new { htmlAttributes = new { @class = "form-control", type = "date", @onchange = "checkDate2(this.value)" } })
and that would be my job:
var checkDate2 = function (obj) {
if (obj._selectedDate > new Date()) {
alert("Você não pode selecionar uma data maior que a data de hoje!");
obj._selectedDate = new Date();
// seleciona a data atual novamente
obj._textbox.set_Value(obj._selectedDate.format(obj._format))
}
}
not only you make the bind of the method
checkDate2
after loading the page?– Leandro Angelo
And note that in the statement
@onchange = "checkDate2(this.value)
you pass the value, while your method waits for the object– Leandro Angelo
I made use of another function almost the same way and it worked, only this one with the date is not going.
– Rodrigo Santos
Example that works: Html.Dropdownlistfor(model => model.Tip_doc, new Selectlist(listdoc, "Text", "Value"), "Select", new { class = "form-control", onchange = "validateDropDown(this.value)" })" var validateDropDown = Function (obj) { if (obj == "C") { Alert('Select a Database'); } Else { Return true; } }
– Rodrigo Santos
You just tried what I said?
@onchange = "checkDate2(this)
? presents how the component in html was rendered and tests with javascript by the console– Leandro Angelo
I arrived yes Leandro and was not, so I ended up doing otherwise, and I made the call on onclick="checkDate2()" that worked and now I’m struggling to buy two date on javascript rsrsr
– Rodrigo Santos
I was able to solve the date question this way: var hoje = new Date(); var emissao = Document.getElementById("Emissao"). value; var emissaolMilisseconds = new Date(issuance). getTime() + 10000000; var hojeMilisseconds = new Date(today). getTime(); if (issuelMilisseconds > hojeMilisseconds) { mgs += "ISSUANCE DATE cannot be higher than today’s date! n"; errors = errors + 1; }
– Rodrigo Santos