JavaScript - Get textbox value using JavaScript

Asked By Ramesh Patel on 03-Jan-07 01:59 AM

I have written following code. but i can't get the value of textbox.

<%@ Page Language="C#" MasterPageFile="~/MasterPage/Default.master" AutoEventWireup="true"

CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

<script language="javascript" type="text/javascript">

function check_user()

{

var str = document.getElementById('txtUsername').value;

alert(str);

}

</script>

<table>

<tr>

<td>

<asp:TextBox ID="txtUsername" runat="server" CssClass="textBox" Width="200px"></asp:TextBox>

<a href="#top" onclick="check_user()">CheckAvailability</a>

</td>

</tr>

</table>

</asp:Content>

Note: I don't wont to form tag.ContentPlaceHolder Must required for me

Thanks

try document.getElementById("<%= txtUsername.ClientID %>").value;

Senthil T. replied to Ramesh Patel on 03-Jan-07 02:07 AM
end of post

document.getElementById('ctl00_ContentPlaceHolder1_txtUsername').value;

K Pravin Kumar Reddy replied to Ramesh Patel on 03-Jan-07 04:51 AM

function check_user()

{

var str = document.getElementById('ctl00_ContentPlaceHolder1_txtUsername').value;

alert(str);

}