Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically Loading and Removing Javascript Functions
    primarykey
    data
    text
    <p>I'm trying to find a way to inject a new JavaScript functions dynamically without having to do a page reload. I have a form for putting in inventory items and I would like to load or remove functions based on which manufacturer is selected. Trying to research this I thought I could accomplish this with:</p> <pre><code>document.getElementsByTagName("head")[0].appendChild </code></pre> <p>The document I was using for examples was taken from <a href="http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml" rel="nofollow">http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml</a>. At first I was not sure if it was calling the file and so as a final test I appended the small snippet:</p> <pre><code>var petname="Spotty" alert("Pet Name: " + petname) </code></pre> <p>and to the end of the .js file and received the alert. I was hoping to make this input page modular and dynamic. The reason I need to replace the functions is because each manufacturer uses what is called a "BOM" number which based on the values gives the unit model, condenser, electrical, etc. The scripting as it stands right now uses the onChange feature so on each drop down selection the BOM number is updated with its correct value. Conversely entering in a BOM number will select the values from the drop down menus. The JavaScript functions work as intended with the onChange's if I place it in the 'head' but when using the .appendChild none of the functions work. Should I be using something else for this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload