I have created a registration form and now I am trying to put null validations on the fields.
All fields are location inside one table like :
<table border="0" cellspacing="5" width="100%">
<tr>
<td width="50%" valign="top">
<span id="ctl00_PageBody_lblFname">Prénom</span>
<strong><font color="#FF0000">*</font></strong><br />
<input name="ctl00$PageBody$txtFname" type="text" id="ctl00_PageBody_txtFname" rel="First Name" />
<br />
<span id="ctl00_PageBody_lblLname">Nom</span>
<strong><font color="#FF0000">*</font></strong><br />
<input name="ctl00$PageBody$txtLname" type="text" id="ctl00_PageBody_txtLname" rel="Last Name" />
</td>
</tr>
</table>
Now using jquery I am trying to create a generic function which iterates through all the text boxes and if they are empty it displays a message mentioning the Field Name :
var Msg = "Please provide values for :";
var nullFieldTracked = 'false';
$('input[type="text"], select').each(function () {
if (this.value == '' && this.hasAttribute("rel")) {
nullFieldTracked = 'true';
Msg += '\n - ' + $(this).attr('rel');
}
});
if (nullFieldTracked == 'true') {
alert(Msg);
return false;
}
Code works like charm, I have added a ‘rel’ attribute to the textboxes in order to read the Field Name, BUT
Now there is a change in the requirement and I need to launch this website in multipul languages and hence it will read the attributes from the resource files and asp.net doesn’t create a meta resource for ‘rel’ tag, So I am thinking to reading the Field Name from the closest Span, but not able to Track.
Kindly help with Jquery.
Thanks a lot in advance.
To retreive value from closest span