• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

validating textboxes

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
zachvaldez
Asked:
zachvaldez
  • 7
  • 7
  • 2
1 Solution
 
Rajkumar GsSoftware EngineerCommented:
Using javascript code, you can achieve this.

Raj
0
 
Rajkumar GsSoftware EngineerCommented:
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
 
disruptCommented:
You can also use something like jformer:

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

to create some nice forms
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
zachvaldezAuthor Commented:
the javascript.. Can that be a universal function not only limited to textbox1? thanks
0
 
disruptCommented:
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
 
zachvaldezAuthor Commented:
nice demo. can that be applied? is it javascript or .net source?
0
 
disruptCommented:
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
 
disruptCommented:
it is jquery (javascript) and yes it can be applied you can download it here:

http://www.jformer.com/download/
0
 
zachvaldezAuthor Commented:
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
 
zachvaldezAuthor Commented:
which one should I download, the produciton or developer.
What about the jquery link provided there? so its jformer..
0
 
disruptCommented:
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
 
disruptCommented:
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
 
zachvaldezAuthor Commented:
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
 
zachvaldezAuthor Commented:
so how will I apply this with regards to the textbox validation(my question?)
0
 
disruptCommented:
I would start with this page:

http://docs.jquery.com/Plugins/validation
0
 
zachvaldezAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 7
  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now