Using Jquery UI "dialog" widget I am trying to dynamically create multiple modal windows.
Inside a php loop I am dynamically creating the buttons that will trigger the modal to open, as well as the div that will be the modal window. Inside the same loop I am doing an echo and writing the javascript to handle the modal windows. My problem is I do not know exactly how to handle writing the javascript. Currently I am not getting any of my modals to work. Should I create a function and call it through each loop iteration or should I publish the entire document.ready routine each iteration?
<script type="text/javascript">
function uiready(a){
$( "#" + a ).dialog({
autoOpen: false,
height: 650,
width: 625,
modal: true
});
$( "#Button" + a )
.click(function() {
$( "#" + a ).dialog( "open" );
});
};
</script>
<?php
//This area should build details buttons if there is a program with an amount greater than $0
for ($i=1; $i<17; $i++){
$ID= $_POST["textfield" . $i];
if ($ID!=""){
echo '<script type="text/javascript">
uiready(' . $i . ');
</script>';
//build a button with the ID equal the post value
echo "<input type=\"button\" value=\" $ID \" id=\"Button" . $i . "\" class=\"btnmargin\" />";
//next build the actual div
echo '<div class="printable' . $i . '" id="' . $i . '">
<table cellspacing="0" cellpadding="10" border="2px">
//for the sake of space I have not included the entire table markup
</table>
</div>';
}
}
?>