Skip to content

Instantly share code, notes, and snippets.

@amcn84
Created August 11, 2017 01:20
Show Gist options
  • Save amcn84/cbbfe0f15b4eccb809123c1e43799b6c to your computer and use it in GitHub Desktop.
Save amcn84/cbbfe0f15b4eccb809123c1e43799b6c to your computer and use it in GitHub Desktop.
addAgentID all forms
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(){
function addAgentID(id,formName,ord) {
var IDlocation = parseInt(ord);
var input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("name", "agentHeaderID");
input.setAttribute("value", id);
document.getElementsByClassName(formName)[IDlocation].appendChild(input);
}
// list of forms to target
var forms = ["IDX-searchForm","IDX-quicksearchForm","equity-quicksearch-form","idx-omnibar-form"];
for(var i = 0, len = forms.length; i < len; i++) {
i = parseInt(i);
formClass = forms[i];
// generate an array of elements with the class we're looking for
var array = document.getElementsByClassName(formClass);
// Let's check and see if we find one of our forms
if(array.length !=0) {
console.log("Awyeah we found "+formClass+" adding our ID");
// found a form but how many more are there, lets hit them all
for(var x = 0, length = array.length; x < length; x++) {
addAgentID("68618",formClass,x);
}
} else {
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