Skip to content

Instantly share code, notes, and snippets.

@amcn84
Last active August 11, 2017 00:58
Show Gist options
  • Save amcn84/9bb9906d969093e550328c04dd3b0a12 to your computer and use it in GitHub Desktop.
Save amcn84/9bb9906d969093e550328c04dd3b0a12 to your computer and use it in GitHub Desktop.
IDX Broker / Equity : Add Agent Header ID to Forms
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(){
function addAgentID(id,formName) {
var input = document.createElement("input"); // Setup the hidden input field
input.setAttribute("type", "hidden");
input.setAttribute("name", "agentHeaderID");
input.setAttribute("value", id); // this is where the given agentHeaderID is used
document.getElementsByClassName(formName)[0].appendChild(input);
}
// List of forms that should be targeted
var forms = ["IDX-searchForm","IDX-quicksearchForm","equity-quicksearch-form","idx-omnibar-form"];
// Let's check for our forms being on the page and if they are add the id to the first one we find
// This could be modified to go through a second array of objects to make sure every form is hit
for(var i = 0, len = forms.length; i < len; i++) {
i = parseInt(i);
formClass = forms[i];
var array = document.getElementsByClassName(formClass);
// Validate that the form was found and if it was inject the new input field
if(array.length !=0) {
console.log("Awyeah we found "+formClass+" adding our ID");
addAgentID("68618",formClass);
} else {
// Testing purposes not a real necessary step but its nice to know which forms we didn't find.
console.log("We couldn't find our form "+ formClass);
}
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment