variable printing

by Ryan Mitchell

HTML

<form id="myForm">Your name:
    <input type="text" id="nametxt" />
    <input type="button" value="submit" id="submit" />
</form>
<div id="test">Click me to test!</div>

JavaScript

var name = "";
    $("#submit").click(function(){    
        name = $("#nametxt").val();
    });
    $("input[type='button']").click(function() {
        alert($("#nametxt").val());
        alert(name);
    });
$("#test").click(function() {
    alert(name);
});