[jQuery] Selecting parent form
Hello,
I'm currently trying to select to parent form when I loose focus on a
inputfield within that form to check the values and enable the submit
button if possible. I want to keep it ass nice as possible (no hard
coding). But selecting the parent form is a pain in the ass.
This is what I did:
[code]$('input.required').blur(function()
{
//looping over them didn't work -> however length says 2forms
found what is correct
$(this).parents().find('form').each(function test(i)
{
if(i==0)this.css.('background-color','red');
else this.css.('background-color','blue');
});
//Nope :)---> looks like always selecting first form
alert( $(this).parents().find('form:last'.attr('id'));
//nothing either
alert( $(this).parents().find('form:first').attr('id'));
}[/code]
Here is the HTML -> you see 2 forms
[code]<form id='addForm' action='<tag:action />'>
<fieldset>
<legend>
<tag:legend />
</legend>
<table border=0>
<tr>
<td colspan="2">
<div id="manageTracklist">
<form id='tracklistform'>
<fieldset>
<legend><tag:manageTracklistTitle /></legend>
<table>
<tr>
<td><tag:trackArtistTitle /></td>
<td><input type='text' class="required" id='track_artist'
name='track_artist' /></td>
</tr>
<tr>
<td><tag:trackTitle /></td>
<td><input type='text' class="required" id='track_title'
name='track_title' /></td>
</tr>
<tr>
<td><tag:trackGenreTitle /></td>
<td><input type='text' id='track_genre' name='track_genre' /></
td>
</tr>
<tr>
<td><tag:trackLengthTitle /></td>
<td><input type='text' id='track_length' name='track_length' /