Bookmarklet – Fill input fields, fire an event then click a button

javascript: {  document.getElementsByClassName('APassAttr')[0].value = 1; document.getElementById('CountryLocationAddress').value = 4020; document.getElementById('CountryLocationAddress').dispatchEvent(new Event('change')); document.getElementsByName('activityTime')[0].value = '00'; document.getElementById('companyAddress').value = 'Mesogeiwn'; document.getElementById('companyCity').value = 'Athens'; document.getElementById('save').click(); void(0) }

beautified :

document.getElementsByClassName('APassAttr')[0].value = 1 //element selector by CLASS (returns an array, then grab the first)
document.getElementById('CountryLocationAddress').value = 4020; //select inputbox
document.getElementById('CountryLocationAddress').dispatchEvent(new Event('change')); //fire event - change
document.getElementsByName('activityTime')[0].value = '00'; //element selector by NAME (returns an array, then grab the first)
document.getElementById('companyAddress').value = 'Mesogeiwn'; //element selector by ID
document.getElementById('companyCity').value = 'Athens'; // set input value
document.getElementById('save').click(); //click button - submit form 

dispatch event – refs :
https://2ality.com/2013/06/triggering-events.html
https://gomakethings.com/custom-events-in-internet-explorer-with-vanilla-js/

click ref :
https://stackoverflow.com/a/3822931/1320686

bookmarklet ref :
https://stackoverflow.com/a/11301539/1320686

By: |08/01/2020|categories: