Click here to Skip to main content
14,735,210 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i want to show value inside textbox and not a label


Everybody shows like

Username : <input type="text" name="loginhere" />

I want to show like

<input type="text" name="loginhere" value="Username" />

when input clicked , the value show disappear , and when input not clicked, and button clicked,
check in jquery if value entered, else show alert
Posted

1 solution

you can do it using HTML5 and jQuery. Please check following code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication2.WebForm2" EnableViewState="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
   <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
   <script type="text/javascript">
       function CheckValue() {
           var userName = $("#userName").val();
           if (userName == '')
           {
               alert('user Name is empty');
           }
           else
           {
               alert(userName);
           }
       }
   </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="text" id="userName" name="userName" placeholder="Username"><br>
     <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="CheckValue()"  />
    </div>

    </form>
</body>
</html>
   
Comments
maulikshah1990 17-Jan-14 0:14am
   
thanks ..but already solved with same code ..
Sandeep Singh Shekhawat 17-Jan-14 0:15am
   
sounds good..Thanks

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