#1 2016-11-09 19:11:00

starin
Banned
Registered: 2016-11-09
Posts: 12

Where to place external Javascript code in our applications

Hi, i added this code in content html control and got Error: "'myMove' is undefined" ,
is there any way to call a function is defined in html?
thanks !

<!DOCTYPE html>
<html>
<style>
#myContainer {
  width: 400px;
  height: 400px;
  position: relative;
  background: yellow;
}
#myAnimation {
  width: 50px;
  height: 50px;
  position: absolute;
  background-color: red;
}
</style>
<body>

<p>
<button onclick="myMove()">Click Me</button>
</p>

<div id ="myContainer">
<div id ="myAnimation"></div>
</div>

<script>
function myMove() {
  var elem = document.getElementById("myAnimation");
  var pos = 0;
  var id = setInterval(frame, 10);
  function frame() {
    if (pos == 350) {
      clearInterval(id);
    } else {
      pos++;
      elem.style.top = pos + 'px';
      elem.style.left = pos + 'px';
    }
  }
}
</script>

</body>
</html>

Last edited by starin (2016-11-09 19:11:45)

Offline

#2 2016-11-09 19:20:23

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: Where to place external Javascript code in our applications

Hello starin,

You must place the Javascript code in some app's/view's/control's event (between the couple "StartJS" and "EndJS" actions) or in an external Javascript file or maybe in an app's Javascript function. Depending on where you place it then you can use it in some or other way. For example, if you place the code in an app's function you can simply call to that function. If you place the code ni an external Javascript file, you must use a bit of Javascript to call it. Take a look at the "External" app sample and also at the "External Javascript" tutorial in the App Builder's help file.

P.S. The CSS code probably can work... but is a good idea to separate it into the app's Inline CSS option or in an external CSS file.

Offline

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.