Reputation: 361
I post via Ajax and get a return value which I then want to insert into an input text field - NOte there are "many" similar forms on the page hence the use of .parent. What is the right JQuery statement please.
Thanks in advance
$j(this).parent('form input[name$="tesitID"]').val(data)
Upvotes: 0
Views: 70
Reputation: 631
The following jQuery should traverse from a trigger inside the form, to the form parent, then find the input and set the value to the supplied data.
$(this).parent('form').find('input[name="testID"]').val(data);
example:
<html>
<head>
<script type="text/javascript" src="jquery.js"> </script>
<script type="text/javascript">
$(function(){
$("#trigger").click(
function(){
$(this).parent('form').find('input[name="testID"]').val('data');
});
});
</script>
</head>
<body>
<form>
<input type="text" value="" name='testID' />
<input type="button" value="Load AJAX" id="trigger" />
</form>
</body>
</html>
Upvotes: 1