-3

Script Code:

<script type="text/javascript">
var uid = 'xxxxx';
var wid = 'xxxxx';
</script>
<script type="text/javascript" src="http://cdn.popcash.net/pop.js"></script>

Button Code:

<div>
<input type="submit" class="btn" value="Get reward!">
</div>

I am a total noob at this..pls help !!

kuldipem
  • 1,719
  • 1
  • 19
  • 32

4 Answers4

0
<div>
   <input type="submit" class="btn" onclick="alert('this is your msg.');" value="Get reward!">
</div>
kuldipem
  • 1,719
  • 1
  • 19
  • 32
0
<input type="submit" id="button1" value="Click Me" onclick="alertThis()">
<script type="text/javascript">
    function alertThis(){
        var var1 = "xxxx";
        var var2 = "yyyy";
        alert(var1+var2);
    }
</script>

That should do it.

Random Integer
  • 106
  • 3
  • 9
0

Your HTML:

<script type="text/javascript">
var uid = 'xxxxx';
var wid = 'xxxxx';
</script>
<input type="submit" class="btn" value="Get reward!" onclick="addPopup()">

Your JS:

function addPopup() {
    var script = document.createElement('script')
    script.setAttribute('src', 'http://cdn.popcash.net/pop.js');
    script.setAttribute('type', 'text/javascript');
    document.getElementsByTagName('head')[0].appendChild(script)
}

This works, if the pop.js will init itself, when included

Mephiztopheles
  • 2,228
  • 1
  • 12
  • 25
0

It seems you want to execute the script when the button is pressed, here is a way to do so:

<script>
  var uid = 'xxxxx';
  var wid = 'xxxxx';

  function showPopup() {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'http://cdn.popcash.net/pop.js';

    document.getElementsByTagName('head')[0].appendChild(script);
  }
</script>

<div>
  <input type="submit" class="btn" value="Get reward!" onclick="showPopup();">
</div>

Although I must tell you that you should be aware of possibles security breaches that executing external javascript files may open. A similar case is found at Dynamically added script will not execute

Community
  • 1
  • 1
gustavotkg
  • 4,099
  • 1
  • 19
  • 29
  • I don't fully recall, but I think I had it written down and then I was testing something related. When I came back I'd submitted it. – gustavotkg Feb 06 '15 at 23:07