I'm having problems setting an input after a jquery load finishes. I've tried the following posts on this site, and have had no success.
- How to wait for div to load before calling another function?
- How to wait until an element exists?
- Do something AFTER the page has loaded completely
No matter what I do, I get the following error "Unable to set property 'value' of undefined or null reference" because the input hasn't loaded by the time setValues is called.
Below is a simplified version of my code (with some things I've tried commented out). I'm running it in IE11 standards mode (no compatability view). Any guidance/help is appreciated. Basically, how do I wait until the inputs are loaded to call setValues?:
frame1.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<input name="input1" id="input1" />
<input name="input2" id="input2" />
</body>
</html>
parentFrame.html
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.10.2.min.js"> </script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div id="div1" style="width:100px;height:100px;border:2px black solid;"> </div>
<div id="div2"> </div>
</body>
<script defer>
function setValues() {
window.document.getElementById("input1").value="TEST";
window.document.getElementById("input2").value="TEST";
}
$(document).ready(function(){
//$("#div1").load("frame1.html", setValues);
$("#div1").load("frame1.html");
});
$(window).load(setValues);
//document.addEventListener( "DOMContentLoaded", setValues, false )
/*
$("div").ready(function(){
window.document.getElementById("input1").value="TEST";
window.document.getElementById("input2").value="TEST";
});
*/
</script>
</html>