1

I have created two form in one page each form having it's own button . when I click a first form button should refresh both form at the same time.

my first form is look like this

<form id="search_form" method="post" action="do_searchID.php"> 
        <label>Enter Employee Number</label>
        <input type="text" name="emp_id" id="emp_id">
        <button type="submit" name="search">Search</button>
</form>

my second form is look like this at the same page

<form method="post" action="do_searchID.php">
<label>Full Name</label>
<input type="text"  id="full_name" value="">
<button type="submit" name="submit_update">Update Now </button>
</form>

from this how can write jquery to do above task. Please help me I have no idea by doing this task I have to retrieve data's from database.

Haither Ali
  • 183
  • 1
  • 10

3 Answers3

1
$("#SearchButton").click(function(){
     // Trigger your submit of both form
     $("#search_form,#ID_form_2").submit();
})

You can use above code. if you have want this to be done on first submit button call.

FORM1

<form id="search_form" method="post" action="do_searchID.php"> 
    <label>Enter Employee Number</label>
    <input type="text" name="emp_id" id="emp_id">
    <button type="submit" id='SearchButton' name="search">Search</button>
</form>

FORM2

<form method="post" id='ID_form_2' action="do_searchID.php">
    <label>Full Name</label>
    <input type="text"  id="full_name" value="">
    <button type="submit" name="submit_update">Update Now </button>
</form>
danish farhaj
  • 1,316
  • 10
  • 20
1

The best approach would be to use a common class to all fields you want to refresh.. and create a function which do that.

Like this.

  function refreshForm()
   {
   $(".commonClass").val('');
   }

thats it.

Anand Singh
  • 2,343
  • 1
  • 22
  • 34
1

You can do this using ajax. I think you are trying to search employee with employee id and show employee name in second form. For that here is ajax code

$(function()){
var emp_id = $('#emp_id').val();
$.ajax({
          url: filename.php,
          data: {'emp_id':emp_id},
          dataType: 'json',
          method:'POST',
            success:function (data)
            {
                var emp_name = data.empname;
                /* If its receiving json in data then parse like JSON.parse(data). Then get employee name*/
                $("#fullname").val('emp_name');
            }
        });
});

In php you can get the emp_id by $_POST['emp_id'] and search the employee name by emp_id and return employee name.

FaNtAMode
  • 159
  • 2
  • 9