Click to See Complete Forum and Search --> : javascript


tis707
October 13th, 2008, 11:27 PM
Hi all

I have textbox(server side) and label
when i enter a value more than 150 need to display an error message like more than 150 and when i enter a value below 30 need to display anoter error

i write a javascript for this but it is not firing

neeed to write in textchange event

txtPress.attribbutes.add("OnTextChanged","return validPress();")
Thanks in advance

eclipsed4utoo
October 14th, 2008, 10:33 AM
you probably don't want to do it with the event "OnTextChanged". That will fire when they type in 1, and they will get the error message.

you may want to try it on the "OnUnload" event.

and your code should probably be this...


txtPress.Attributes.Add("onunload", "validPress();");


if that doesn't work, you can write the entire javascript function in the code behind, using a StringBuilder

kinda like this:


StringBuilder sb = new StringBuilder();
sb.Append("<script language='javascript'>");
sb.Append("alert('Hi');");
sb.Append("<");
sb.Append("/script>");

txtPress.Attributes.Add("onunload", sb.ToString());

mmetzger
October 14th, 2008, 09:18 PM
OnBlur will likely be the best option, though you'll want to make sure to have full validators on the fields anyway in case javascript is disabled.