user3262364 user3262364 - 6 months ago 13
HTML Question

not able to validate text box using java script

my input text box source like this:

<asp:TextBox ID="TxtDepCode" runat="server" Height="18px"></asp:TextBox>


and my javascript function like this:

<script type="text/javascript" language="javascript">
function confirm_user() {
var userPass = document.getElementById('TxtDepCode');
alert(userPass)
if (userPass=''){
alert("value is blank")
}
if (confirm("Department already available, would you like to update ?") == true)
return true;
else
return false;
}
</script>


in submit button click i want to check wethar corresponding text is empty or not
my submit button click event like this:


Answer
var userPass = document.getElementById('TxtDepCode').value;

Or

var userPass = document.getElementById('<%=TxtDepCode.ClientID%>').value;

Modify the first line of function to get value of textbox as above

if (userPass==''){

Modify if as above