Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to retrieve value from text boxes to do validation.

However when I am trying to get value from a text box I get undefined value.

my code for button is :
<asp:LinkButton ID="lbLogin" runat="server" OnClientClick="Validation()" OnClick="btnLogin_Click" ValidationGroup="Submit">Login</asp:LinkButton>



text box is:

<asp:TextBox ID="tbPassword" runat="server" TextMode="Password" Width="124px"
CssClass="textbox"></asp:TextBox>

And function is :

function Validation() {
           var password = $("#tbPassword").val();
           alert(password);
       }



Alert always show "undefined". Is there anything wrong in my function?
Posted
Updated 29-Mar-12 23:28pm
v2

Hey Try This

if u used master page then

C#
function Validation() {
                  
           var pwd = document.getElementById('cntPlcHolder_tbPassword').value;
           alert(pwd);
       }

other wise

XML
<pre lang="cs">function Validation() {

           var pwd = document.getElementById('tbPassword').value;
           alert(pwd);
       }</pre>


best luck
 
Share this answer
 
v3
Comments
Nilesh Patil Kolhapur 30-Mar-12 5:47am    
give rpy
tejashri.gandhi 30-Mar-12 7:21am    
Thanks Nilesh,
This also works, however i am using solution as: var password = $.trim($("#<%=tbPassword.ClientID %>").val())

Thank you so much for Help...
Nilesh Patil Kolhapur 3-Apr-12 0:21am    
welcome
try this

JavaScript
//jquery
$( document ).ready( function () {
           var val = $( '#tbNewPassword' ).val();
           alert( val );
       } );
//javascript
 function Validation()  {
            var val = $( '#tbNewPassword' ).val();
            alert( val );
        }
 
Share this answer
 
v3
Comments
tejashri.gandhi 30-Mar-12 5:29am    
Sorry I copy pasted wrong button code...I have done same thing that you are showing
Bojjaiah 30-Mar-12 5:39am    
what you got error?
try this.. and dont use validation control and javascript both at time.

VB
<asp:Button ID="btnSave" runat="server" CssClass="button save" OnClick="btnSave_Click"
                                        OnClientClick="javascript:return ValidateSaveRegion()" AccessKey="s"
                                        Text="Save" ValidationGroup="a" />
 
Share this answer
 
Comments
tejashri.gandhi 30-Mar-12 5:31am    
i tried this, but again same issue
I was doing mistake of giving id as it was

When i tried like this it works :

var password = $.trim($("#<%=tbPassword.ClientID %>").val())
 
Share this answer
 
Comments
Kiirrii 30-Mar-12 5:55am    
good...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900