1

I have a form that contains various tables. These tables are shown or hidden when the next button is clicked. So this virtually provides a navigation to the user from one page to another while the form is same and just the tables are shown/hidden. Now what I need is validate these table on click of next button (a hyperlink type) and show a validation summary each time. I know validate can be used for the whole form but I need to just validate the table elements and then show the summary.

Keep in mind that I am using non obtrusive client side validation, the elements are being created using that model thing. Also, it currently does that validation but on submit button at the end. very brief sample of my table

<table id= "table1">
    <tr>
        <td1>First coulmn</td1>
        <td2>value2</td2>
        <td3>
            <a id="Next" onclick= "javascript:function1()">Save</a>
        </td3>
    </tr>
</table>
3
  • 1
    can you post the rest of the code so I can see what function1 does etc? Commented Nov 21, 2012 at 22:36
  • You can call $("#id").valid() where #id identifies a form field rather than the entire form. Commented Nov 21, 2012 at 22:57
  • 1
    hm.. Are tags td1,td2,td3 valid? Commented Nov 21, 2012 at 22:58

1 Answer 1

0
<table id= "table1">
    <tr>
        <td1>First coulmn</td1>
        <td2>value2</td2>
        <td3>
            <a id="Next" onclick= "javascript:validAndNext('1')">Save</a>
        </td3>
    </tr>
</table>
    .
    .
    .
<table id="tableN"> 

function validAndNext(table_id){
   var table = $('#table'+table_id);
   var inputs = table.find("input");
   var valid = true;
   inputs.each(function(){
       // A type of validation is:
       if($(this).val().length<=0) valid = false;                
   });
   if(valid){
      table.hide();
      $('#table'+(table_id+1)).show();
   }else alert('Your table is not valid!');
}
Sign up to request clarification or add additional context in comments.

3 Comments

can you please elaborate what you have done with Valid $(this).val();?
Thanks a ton man, that really works. But can you also advise how can I show a summary of errors for each of these fields on the top of the form? Thanks
And also if $(this).val(); checks for elements which have validation class against them or for all?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.