?
Solved

validating textboxes

Posted on 2011-10-19
16
Medium Priority
?
174 Views
Last Modified: 2012-05-12
I have a label after a textbox markes '*" as a warning that it is a 'must field'.
When it is populated it removes the '*" and when there is no entry put back the " label.

Can this be done other than the validating controls?
0
Comment
Question by:zachvaldez
  • 7
  • 7
  • 2
16 Comments
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 36993325
Using javascript code, you can achieve this.

Raj
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 36993400
This is a sample code -
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    
    <script language="javascript" type="text/javascript">
        function validate() {
            var textboxValue;
            textboxValue = document.getElementById("TextBox1").value;

            if (textboxValue == "")
                document.getElementById("Label1").innerHTML = "*";
            else
                document.getElementById("Label1").innerHTML = "";
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" OnKeyUp="validate();"></asp:TextBox>
        <asp:Label ID="Label1" runat="server"
            Text="*"></asp:Label>
    </div>
    </form>
</body>
</html>

Open in new window

0
 
LVL 16

Expert Comment

by:disrupt
ID: 36993426
You can also use something like jformer:

http://www.jformer.com/demos/contact/

to create some nice forms
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:zachvaldez
ID: 36993498
the javascript.. Can that be a universal function not only limited to textbox1? thanks
0
 
LVL 16

Expert Comment

by:disrupt
ID: 36993522
Yes so long you have it pointing to the correct value for instance if you had a dropdownlist you can use:

$("#dropdownidhere option:selected").text();

instead of

document.getElementById("TextBox1").value;

I am using jquery in this example so you would need a reference to jquery like so:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
0
 

Author Comment

by:zachvaldez
ID: 36993536
nice demo. can that be applied? is it javascript or .net source?
0
 
LVL 16

Expert Comment

by:disrupt
ID: 36993543
if you look at jformer it has built in validation and is very easy to pass validation on controls like so:

http://www.jformer.com/demos/team/

and you can set min/max etc
0
 
LVL 16

Expert Comment

by:disrupt
ID: 36993548
it is jquery (javascript) and yes it can be applied you can download it here:

http://www.jformer.com/download/
0
 

Author Comment

by:zachvaldez
ID: 36993555
I already have the <script> tag. Im not familiar with jquery but willing to learn though. should I chaneg somehting on the page script tags to reference it?
0
 

Author Comment

by:zachvaldez
ID: 36993565
which one should I download, the produciton or developer.
What about the jquery link provided there? so its jformer..
0
 
LVL 16

Expert Comment

by:disrupt
ID: 36993568
you can have multiple script tags, if you want to go that route I would download it and you can see the deomos in your download on how it works.

if you don't want to use the aspx validation controls jquery is a nice solution.  Jquery is a cross-browser javascript library
0
 
LVL 16

Expert Comment

by:disrupt
ID: 36993577
for jquery don't worry about that you can use

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>

that will take care of jquery for you (hosted by google)

the production download is minified so its optimized for production I would go with that one if you plan to use it on a live website
0
 

Author Comment

by:zachvaldez
ID: 36993852
step by step here..
So I added the library in the page(link you sent)
so what next to implement.

BTw this form will be in a website soon but not now...
0
 

Author Comment

by:zachvaldez
ID: 36994220
so how will I apply this with regards to the textbox validation(my question?)
0
 
LVL 16

Accepted Solution

by:
disrupt earned 1000 total points
ID: 36997157
I would start with this page:

http://docs.jquery.com/Plugins/validation
0
 

Author Comment

by:zachvaldez
ID: 37002261
Btw how would I force he page or move  ower so  user can see the grid they entered instead of defaulting to top page?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question