zachvaldez
asked on
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?
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?
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>
You can also use something like jformer:
http://www.jformer.com/demos/contact/
to create some nice forms
http://www.jformer.com/demos/contact/
to create some nice forms
ASKER
the javascript.. Can that be a universal function not only limited to textbox1? thanks
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("T extBox1"). 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"></s cript>
$("#dropdownidhere option:selected").text();
instead of
document.getElementById("T
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"></s
ASKER
nice demo. can that be applied? is it javascript or .net source?
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
http://www.jformer.com/demos/team/
and you can set min/max etc
it is jquery (javascript) and yes it can be applied you can download it here:
http://www.jformer.com/download/
http://www.jformer.com/download/
ASKER
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?
ASKER
which one should I download, the produciton or developer.
What about the jquery link provided there? so its jformer..
What about the jquery link provided there? so its jformer..
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
if you don't want to use the aspx validation controls jquery is a nice solution. Jquery is a cross-browser javascript library
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"></s cript>
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
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></s
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
ASKER
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...
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...
ASKER
so how will I apply this with regards to the textbox validation(my question?)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Btw how would I force he page or move ower so user can see the grid they entered instead of defaulting to top page?
Raj