Skip to content

Instantly share code, notes, and snippets.

@matherton
Created January 22, 2014 10:25
Show Gist options
  • Save matherton/8556512 to your computer and use it in GitHub Desktop.
Save matherton/8556512 to your computer and use it in GitHub Desktop.
Example of how to do a simple AJAX injection of a datepicker field on an onClick event. NOTE requires to be run on a server (I use Apache) and the file being injected is stored in a test folder.
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="../css/ui.css">
</head>
<body>
<div id="tempload"></div>
<button id="btntest" name="btntest">test</button>
<script type="text/javascript">
$(document).ready(function(){
$('#btntest').click(function(){
$.get("test/test.html",function(data){
$('#tempload').html(data);
});
});
});
</script>
</body>
</html>
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
<span class="tips" title="Please enter &lt;br/&gt;the required information!">
<label class="tripDay">
<input type="text" placeholder="From" id="datepicker">
</label>
</span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment