Reputation: 1411
Is it possible to move (or focus) the form tag to a different div and only echo the values of that particular div with jQuery?
Both divs contain 2 input fields with the same name/id:
<input type="text" name="fname" id="fname" value="" placeholder="First Name">
<input type="text" name="lname" id="lname" value="" placeholder="Last Name">
I only want to submit the fields of 1 div which has the focus.
See my jsfiddle:
Upvotes: 0
Views: 84
Reputation: 894
You'll need somewhere to store input or equal to div in which the last focus.
As an example of a functional demo:
$(document).ready(function() {
var last_focus='';
$("input").blur(function(){
last_focus=$(this).parents("div");
})
$('#hit').click(function() {
alert(last_focus.find('input:first').val() + ' ' + last_focus.find('input:last').val());
});
});
Upvotes: 1