Reputation: 59
I want to Create div dynamically with unique id.. base on id we need to get values form the database ..but here can get id but divTag.innerHTML= not getting id to execute my sql query please help me out thanks in adnvce
.dynamicDiv {
width:200px;
height:100px;
border:solid 1px #c0c0c0;
background-color:#e1e1e1;
font-size:11px;
font-family:verdana;
color:#000;
padding:5px;
}
.dynamicDiv{ float:left;}
</style>
<script type="text/javascript" language="javascript">
function createDiv($id)
{
var id =$id;
var divTag = document.createElement("div");
var id =$id;
divTag.id = "div1";
divTag.setAttribute("align","center");
divTag.style.margin = "100px auto";
divTag.className ="dynamicDiv";
divTag.innerHTML = "<?php $sql =mysql_query("SELECT * FROM TABLE WHERE ID='$id'");
$res = mysql_fetch_array($sql);
print_r($res);
?>";
document.body.appendChild(divTag);
}
</script>
</head>
<body style="float:left;">
<div style="float:left;">
<b>Click this button to create div element dynamically</b>
<input id="btn1" type="button" value=
"create div" onClick="createDiv('<?php echo rand(); ?>');" />
Upvotes: 0
Views: 1929
Reputation: 148180
You can not bring data from server with sending call to server, You can use jquery ajax to bring the data and pass the id to filter the data.
Upvotes: 4