I have a page that pulls items from a database and displays them in an iframe. The page is a mix of html, javascript and php. My problem is with the javascript, so I'm posting it here. The php code looks like this:
PHP Code:
<?php
include "connect_to_db.php";
$result = mysqli_query($conn, "SELECT * FROM ButtonsTest");
$rows = mysqli_num_rows($result);
for ($items=1; $items <= $ButtonsPerPage; $items++){
$data = mysqli_fetch_array($result);
?>
document.write ('<td valign="top" align="center"><br><a href="ShowButton.php"><img src="graphics/Buttons/<?php echo"$data[5]"?>"
style="border:0" height=100px></a><p><?php echo"$data[1]"?><br>$<?php echo"$data[2]"?>');
if (<?php echo"$data[3]"?> > 1){
document.write('<br>Qty: ');
}
if (<?php echo"$data[3]"?> > 0){
document.write ('<br><input type="submit" name="button" value="Add to Cart" style="background-color: #A7A5A5;" onclick="AddToCart(<?php echo"$data[0]"?>)"></td>');
}else{
document.write ('<br>Sold</td>');
}
i = i + 1;
document.write("</td><td width=20px></td>");
if (i == ButtonsPerRow){
document.write("</tr><tr>");
i = 0;
}
</script>
<?php
}
?>
When the "button" is clicked, it calls a function, passing the associated database row index ($data[0]). The function looks like this:
Code:
function AddToCart(dbid){
document.write('<form method="POST" id="Form" name="Form" action="updatedb.php?pointer=' + dbid + '">');
document.forms["Form"].submit();
}
This works fine in all browsers I've tried (Chrome, Firefox, Opera, Safari), but will not work in IE. The function is called and the db index is passed, but it doesn't seem to execute the document.write code.
I'm not that familiar with the intricacies of IE, so I don't know what it doesn't like.
Bookmarks