CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: javascript

  1. #1
    Join Date
    Jan 2005
    Posts
    224

    javascript

    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

  2. #2
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: javascript

    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...

    Code:
    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:

    Code:
    StringBuilder sb = new StringBuilder();
    sb.Append("<script language='javascript'>");
    sb.Append("alert('Hi');");
    sb.Append("<");
    sb.Append("/script>");
    
    txtPress.Attributes.Add("onunload", sb.ToString());

  3. #3

    Re: javascript

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured