FutureWithIT
FutureWithIT

Reputation: 65

How to clear the text box on load if a value is already loaded?

I have written a script to load the id if a certain drop-down is selected. But now I need to clear the text box on load to make sure that no previous data is been saved to the data base and the newly added data is only been taken. Following is the code I have written. Please help me to do it right.

$(document).ready(function () {
    $('#selseriessetupid').change(function () {
        $('#employeenumber').val($('#selseriessetupid').val());
        //$('#employeenumber').val("");
    });
});

Upvotes: 2

Views: 168

Answers (2)

Alok Mali
Alok Mali

Reputation: 2881

There is two ways to do that.

First, You can clear the value on the load of the page.

$(document).ready(function () {
  $('#employeenumber').val("");
  $('#selseriessetupid').change(function () {
    $('#employeenumber').val($('#selseriessetupid').val());
  });
});

Second, Trigger change selseriessetupid on the load of the page.

   $(document).ready(function () {
     $('#selseriessetupid').change();
     $('#selseriessetupid').change(function () {
       $('#employeenumber').val($('#selseriessetupid').val());
     });
   });

Upvotes: 1

Vijay Joshi
Vijay Joshi

Reputation: 959

Just clear the textbox inside document.ready.

$(document).ready(function () {
    $('#employeenumber').val("");
    $('#selseriessetupid').change(function () {
        $('#employeenumber').val($('#selseriessetupid').val());
    });
});

Upvotes: 2

Related Questions