lundi 12 mai 2014

How do I add onclick events to dynamically created buttons that runs a JS function from an external file?


Vote count:

0




I currently have a HTML page, 2 JS files and a php file. The HTML calls the 1st JS file that calls the PHP which dynamically creates the page. On the generated page there are several items with buttons underneath them.


I want these buttons to trigger a function in the 2nd JS file.


PHP File:



<head>
<script type="text/javascript" src="js2.js"></script>
</head>
<?php
$i = 0;
for($i=0,$i<3,i++)
{
echo 'Do '.$i;
echo '<input value="Do it" type="button" onclick="doit('.$i.')"/>';
}
?>


The second JS file:



function doit(p1)
{
//code here
}


asked 56 secs ago






Aucun commentaire:

Enregistrer un commentaire