1

How do we achieve validationgroup functionality present in asp.net using only HTML5? I am using this library: http://afarkas.github.com/webshim/demos/demos/webforms/4-webforms-custom-validity.html

Basically I have a textbox and button and I want this textbox and this button to into one group and the rest can be in different group. So this button should only validate for the single textbox and not the entire form.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Jack
  • 7,433
  • 22
  • 63
  • 107
  • some moron downvoted my valid question :) – Jack Nov 02 '12 at 12:16
  • Jack, I'm not the one who downvoted you, but we don't call people morons over here. Learn some manners. On the topic of your question, what have you tried? The lack of obvious effort is probably the reason of your previous downvote. – MarioDS Nov 02 '12 at 13:20
  • @MarioDeSchaepmeester: What could I have tried before I know anything about it? If you happen to read the question you will come to know that I've provided the link to the library which I am using and have tried it's API. – Jack Nov 04 '12 at 04:05
  • @MarioDeSchaepmeester: By the way I've seen moron keyword many times on SO. As a matter of fact, even these users have their names as morons: http://stackoverflow.com/users/870481/moron http://stackoverflow.com/users/22987/the-happy-moron http://stackoverflow.com/users/1203815/fighting-it-morons http://stackoverflow.com/questions/184618/what-is-the-best-comment-in-source-code-you-have-ever-encountered Do you need more links? – Jack Nov 04 '12 at 04:06

1 Answers1

2

You can call checkValidity() on the individual form elements and then take whatever action you deem appropriate. Here is a simple example:

<div id="d1">
    <input type="text" required id="i1">
    <button onclick="if (document.getElementById('i1').checkValidity())
        {document.getElementById('d1').className = 'va'} 
      else 
        {document.getElementById('d1').className = 'in'}; return false;">Check 1</button>
</div>

Obviously in real life you wouldn't use a hacky inline event handler but the principle would be the same.

robertc
  • 74,533
  • 18
  • 193
  • 177