I’m creating a validation script for a multi-step form, each group is inside a table and I want to check that the containing table has a required field inside it.
I’ve tried to implement this as below:
(where a = table id
.required = class, but the classes are like class = “something required”)
function validForm(a) {
var myVar = $('a').find('.required').val();
alert(myVar);
}
the problem is that this code returns undefined. This is my first time using a .find function and I am having a hard time understanding how to use it.
HTML:
<table id = "default">
<tr><td>Default</td></tr>
<tr><td>Field name</td><td><input type="text" name="first_name" maxlength="35" class="txtfield-cu1 required" title="First Name"></td></tr> <- repeat a couple of times
if
ais the table id, you will need to select by$('#a')instead of$('a').In jQuery selection (and CSS)
'#a'selects the tag with id ='a', whereasaselects the<a>tag.Edit: if
ahere stands for a variable that represents the id of the table, then you can use$(a)to select it.Edit 2: jsfiddle link