jQuery - Setting Values from Controls

Use val().


// Textbox, TextArea
let foo = "Hello World";
$('#DemoText').val(foo);

 

Drop Down List

Use val(). You can also set the index like with selectedIndex.


// Drop Downs
let fruit = "b";
$("#Fruit").val(fruit);
$("#Fruit2")[0].selectedIndex = 2;

 

Checkboxes

This example will use the jQuery to find all elements with a type of checkbox and will set the attribute of checked to true.


$( function () { $(':checkbox').attr('checked', true); } );

 

Radio Buttons

Here's an example of how to check and set a radio button.

By Address By Zip Code

$("#radZipCodes").prop('checked', true);