How to set value of input text using jQuery How to set value of input text using jQuery jquery jquery

How to set value of input text using jQuery


Your selector is retrieving the text box's surrounding <div class='textBoxEmployeeNumber'> instead of the input inside it.

// Access the input inside the div with this selector:$(function () {  $('.textBoxEmployeeNumber input').val("fgg");});

Update after seeing output HTML

If the ASP.NET code reliably outputs the HTML <input> with an id attribute id='EmployeeId', you can more simply just use:

$(function () {  $('#EmployeeId').val("fgg");});

Failing this, you will need to verify in your browser's error console that you don't have other script errors causing this to fail. The first example above works correctly in this demonstration.


Using jQuery, we can use the following code:

Select by input name:

$('input[name="textboxname"]').val('some value')

Select by input class:

$('input[type=text].textboxclass').val('some value')

Select by input id:

$('#textboxid').val('some value')


$(document).ready(function () {    $('#EmployeeId').val("fgg");    //Or    $('.textBoxEmployeeNumber > input').val("fgg");    //Or    $('.textBoxEmployeeNumber').find('input').val("fgg");});