Citizen SP
Citizen SP

Reputation: 1411

Move form tag to active div

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:

http://jsfiddle.net/myRJH/

Upvotes: 0

Views: 84

Answers (1)

Pesulap
Pesulap

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());
   });
});

Demo

Upvotes: 1

Related Questions