JQuery - Cheatsheet

Here are some very basic tips for using JQuery

Assuming a webpage that has the following

1
2
3
<span id="SparseTable"></span>
<input id="SparseId" type="text" />
<select id="SparseDefRowRow"></select>

Injection - Adding data to a form (for example populating the sparseTable tag:

1
$('#SparseTable').html(msg.d);

Getting a value from a textbox

1
var sparseId = $("#SparseId").val();

val() works for a dropdown control as well to pull data.

Putting a value into a textbox.

1
$("#SparseId").val("*");

Dropdown controls
Injection - Here is how to quickly add options to a dropdown. (assuming D is <oop… etc.

1
$('#SparseDefRowRow').html(d);

Putting a value into a dropdown (assuming you have an option with a value of ‘*’)

1
$("#ddl_TblStoredQueryId").val("*");