Hi there,
Probably the easiest way -- provided that the group of inputs is
always contained within a paragraph -- is to do this:
$(this).parents('p').find('input.required.spell').val(newText);
The .prev() method selects the immediately previous sibling element.
Your radio buttons have no siblings other than each other (and text
nodes, which aren't included in jQuery selectors).
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Apr 13, 2008, at 12:34 PM, Up-Works wrote:
I have this block of HTML:
<snip>
<p>
<label for="playerName">Player Name: </label>
<input type="text" name="playerName-0" class="required spell"
minlength="2"/>
<span class="spellResponse">
<br/> Did you mean: <span
style="color:#295DAD;"><em><strong><span class="correctWord">Robert</
span></strong></em> Yes: <input type="radio" value="Y" class="spellQ"
name="spellQ"> No: <input type="radio" value="N" class="spellQ"
name="spellQ"></span><br/></span>
</p>
</snip>
I am using a click function on the input.spellQ that if value==Y it
grabs the text() from span.corretWord and places it in the previous
input.required.spell.
I am having trouble selecting the previous input.required spell.
Here is what I have for the funtion:
$('.spellQ').livequery('click',function() {
var qValue = $(this).val();
if(qValue == 'Y') {
var newText = $('span.correctWord').text();
var field = $('input.spell');
//This line below does not work :-(
$(this).prev(field).val(newText);
//console.log(newText);
//console.log(field);
}
});
Thank you in advance for suggestions or assistance.