Passing a variable to function that calls load()

Passing a variable to function that calls load()

Trying to pass res from input form to doIt().


<input>
<div id="search">search</div>


<div id='first'></div>
<p></p>
<div id='second'></div>

<script>
var res;
$("#search").click(
function() {
res=$("input").val();
alert(res);
doIt();
}
);
function doIt() {
$('#first').load("Matthew1.txt",
function(data,status) {
var myArray;
                // I want to set this to the value in input form.
//var res=/\d+\s.*Jacob.*[.;:,]/g;
while ((myArray = res.exec(data)) !== null) {
//alert(myArray[0]);
//text+=myArray[0]+"<br><br><br>";
$("#second").append(myArray[0]+"<br><br><br>");
}
}
).css("white-space", "pre-line").hide();
}
</script>

It seems res doesn't get passed to load(). I want to set res to the value in the input form.