Client Side Validations using .js file
-
any one over here help me please . I using a .js file for client side validations. Ihave written the validation function in th .js file and when I click the button it has to validate the control(TextBox).But it is not working . I am able to go into the .js file but the code (if condition) is not executed. I give my code as below (C#) Validations.js function validate() { window.alert(".js File"); // I am able to get this alert but if // condition is not checked when textbox is null if(document.getElementById ("<%=txtName.ClientID %>").value=="") { window.alert("Name Feild can not be blank"); document.getElementById("<%=txtName.ClientID%>").focus(); return false; } } Validate.aspx ; when i click on the button without entering a value into the textbox i am not getting the alert message "Name Feild can not be blank". please help me. :) Kovuru Sreedhar :)
-
any one over here help me please . I using a .js file for client side validations. Ihave written the validation function in th .js file and when I click the button it has to validate the control(TextBox).But it is not working . I am able to go into the .js file but the code (if condition) is not executed. I give my code as below (C#) Validations.js function validate() { window.alert(".js File"); // I am able to get this alert but if // condition is not checked when textbox is null if(document.getElementById ("<%=txtName.ClientID %>").value=="") { window.alert("Name Feild can not be blank"); document.getElementById("<%=txtName.ClientID%>").focus(); return false; } } Validate.aspx ; when i click on the button without entering a value into the textbox i am not getting the alert message "Name Feild can not be blank". please help me. :) Kovuru Sreedhar :)
kvsreedhar wrote:
f(document.getElementById ("<%=txtName.ClientID %>").value=="")
Why dont you try like this?
if(document.getElementById ('txtName').value=='')
please don't forget to vote on the post that helped you.
-
kvsreedhar wrote:
f(document.getElementById ("<%=txtName.ClientID %>").value=="")
Why dont you try like this?
if(document.getElementById ('txtName').value=='')
please don't forget to vote on the post that helped you.
:rose:Thanks Imran it's working.:rose: But a small doubt , when I used the same code as an InLine code (in .aspx script tag and did not use .js file), it worked . what's the concept behind. please clear my doubt Thanks in advance
Kovuru Sreedhar
-
:rose:Thanks Imran it's working.:rose: But a small doubt , when I used the same code as an InLine code (in .aspx script tag and did not use .js file), it worked . what's the concept behind. please clear my doubt Thanks in advance
Kovuru Sreedhar
kvsreedhar wrote:
But a small doubt , when I used the same code as an InLine code (in .aspx script tag and did not use .js file), it worked . what's the concept behind.
Problem was that you have put txtName.ClientID in double quote so that It was worked as string.
please don't forget to vote on the post that helped you.
modified on Monday, August 4, 2008 3:04 AM
-
kvsreedhar wrote:
But a small doubt , when I used the same code as an InLine code (in .aspx script tag and did not use .js file), it worked . what's the concept behind.
Problem was that you have put txtName.ClientID in double quote so that It was worked as string.
please don't forget to vote on the post that helped you.
modified on Monday, August 4, 2008 3:04 AM
I have tried but not working ( .js code) if(document.getElementById('+<%txtName.ClientID%>+').value=='') { window.alert("Name Feild can not be blank"); return false; }
Kovuru Sreedhar
-
I have tried but not working ( .js code) if(document.getElementById('+<%txtName.ClientID%>+').value=='') { window.alert("Name Feild can not be blank"); return false; }
Kovuru Sreedhar
kvsreedhar wrote:
I have tried but not working
Yeah.It didn't work. Sorry,I modified my previous post
please don't forget to vote on the post that helped you.
-
any one over here help me please . I using a .js file for client side validations. Ihave written the validation function in th .js file and when I click the button it has to validate the control(TextBox).But it is not working . I am able to go into the .js file but the code (if condition) is not executed. I give my code as below (C#) Validations.js function validate() { window.alert(".js File"); // I am able to get this alert but if // condition is not checked when textbox is null if(document.getElementById ("<%=txtName.ClientID %>").value=="") { window.alert("Name Feild can not be blank"); document.getElementById("<%=txtName.ClientID%>").focus(); return false; } } Validate.aspx ; when i click on the button without entering a value into the textbox i am not getting the alert message "Name Feild can not be blank". please help me. :) Kovuru Sreedhar :)
in place of document.getElementById("<%=txtName.ClientID%>").focus(); u write document.getElementById('<%=txtName.ClientID%>').focus(); this will work perfectly.
-
in place of document.getElementById("<%=txtName.ClientID%>").focus(); u write document.getElementById('<%=txtName.ClientID%>').focus(); this will work perfectly.
thank you for your help and time.
Kovuru Sreedhar