Reputation: 11725
The problem i'm having is though it's passing the function Username, it`s not displaying the * after passing the
$("#Name").text("*"); In debug mode in Mozilla, it displays undefined! What is wrong or what have I missed?
I have @Html.Label("Name", "")
and
$('#changePassword').click(function () {
if (Username()) {
$("#changePassword").dialog('open');
return false;
}
});
function Username() {
if ($("#Name").val() == "") {
$("#Name").text("*");
return false;
}
else {
return true;
}
}
Upvotes: 0
Views: 6346
Reputation: 1038720
When you write @Html.Label("Name", "")
no HTML is generated which is a bit strange but this is how this helper is implemented. @Html.Label("Name", " ")
the following HTML will be generated:
<label for="Name"> </label>
Notice that there is no id. So you cannot reference the label with $('#Name')
. You need to use the following:
$('label[for=Name]').html('*');
Upvotes: 7