How can I load multiple javascripts on the same page?

  • 0
  • 1
  • Question
  • Updated 3 years ago
  • Answered

I'm trying to load different javascripts to a form. For example, I have one that will embed a search button to a field and I'd like to replicate this functionality to another field.

I've tried using the Image Onload Technique, but it seems to allow only one at a time.

Photo of Carlos

Carlos

  • 796 Points 500 badge 2x thumb

Posted 3 years ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
Within module.js you can load additional scripts and after they have loaded continue with you specific code:

$.when(
  $.getScript(url1),
  $.getScript(url2)
).then(function() {
  // your code here
});

Bear in mind that you generally want to do as few AJAX calls as possible.
Photo of Taylor

Taylor

  • 52 Points
Hi Dan, I have a similar situation. My module.js is used to load an html table onto the form. Now I'd like to load a second (and different) html table on to the form. Should my script be something like:

$.when(
  $.getScript(url1)
).then(function() {
  // table 1 code here
,
$when(
  $.getScript(url2)
).then(function() {
  // table 2 code here
});

Also, what are the urls supposed to be here? Is it the database or the page...or something else?
Thanks!