Reputation: 371
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:
Upvotes: 1
Views: 35
Reputation: 8545
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
Upvotes: 1
Reputation: 16814
The crucial issues in the code are as follows:
Get the value of the password and not the element:
var userPass = document.getElementById('TxtDepCode').value;
Change the if to == or === instead of single =
if (userPass == '') {
You are using <asp:TextBox>
that can have a dynamic ID. Therefore you should get the dynamic ID using .NET's ClientID
:
var userPass = document.getElementById('<% =TxtDepCode.ClientID %>').value;
Upvotes: 1
Reputation: 635
You need to return false if value is blank too
<script type="text/javascript" language="javascript">
function confirm_user() {
var userPass = document.getElementById('TxtDepCode');
alert(userPass)
if (userPass.value == ''){ // == not = and userPass.value
alert("value is blank");
return false; // Need to stop the function
}
if (confirm("Department already available, would you like to update ?") == true)
return true;
else
return false;
}
Upvotes: 0