We have code in our website that does a comparsion to what was stored in the database with what the user types in the textbox. This functionality works as is. But, I wanted to add some code to to set a empty string value that shows up in the “lbl_hiredate_change” and set it equal to the string “blank”. I added the if statement with the comment “//my addition” in the below code. Can someone suggest something that will work (this doesn’t). I only want to convert the “” to “blank” at runtime, and don’t want that saved in the database.
Thanks,
Brad.
ASP.Net Code:
<div>
<asp:TextBox ID="tb_hiredate" CssClass="showOriginal required date"
title="Please enter the date this person was hired" runat="server"></asp:TextBox>
<asp:Panel ID="show_hiredate_changed" CssClass="showOriginalLine" runat="server">
(was: <asp:Label ID="lbl_hiredate_changed" CssClass="showOriginalValue was-label" runat="server"></asp:Label>)
</asp:Panel>
</div>
Javascript:
$(document).ready(function () {
$('input.showOriginal').change(function (e) {
showOriginal($(this));
});
});
function showOriginal(theControl) {
var thePanel = theControl.siblings('.showOriginalLine');
var theWasLabel = thePanel.find('.showOriginalValue');
if (theControl.val() == theWasLabel.html()) {
thePanel.css('display', 'none');
}
else {
//my addition.
if ($('.was-label').val() == '') {
$(this).val('blank');
}
thePanel.css('display', 'block');
}
}
Use
text()instead ofval()Read more about val(), text(), html()