AJAX
Basics
Data
DOM
Effects
Events
Forms
jQuery UI
Plug Ins
Traversing
Use val()
.
// Textbox, TextArea
let foo = "Hello World";
$('#DemoText').val(foo);
Use val()
. You can also set the index like with selectedIndex
.
// Drop Downs
let fruit = "b";
$("#Fruit").val(fruit);
$("#Fruit2")[0].selectedIndex = 2;
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); } );
Here's an example of how to check and set a radio button.
By Address By Zip Code
$("#radZipCodes").prop('checked', true);