soulblader_86
Supremacy Member
- Joined
- Sep 28, 2007
- Messages
- 9,012
- Reaction score
- 0
Code:
<!doctype html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<title>Javascript Create Div Element Dynamically</title>
<style type="text/css">
.ex
{
width:auto;
position: relative;
height:auto;
margin:5px;
float :left;
border: 1px solid #000;
}
.square
{
width: 200px;
height:200px;
background-color:#F99;
margin:15px;
}
.myimage {
position: absolute;
top: 0;
left: 0;
z-index: 10;
}
#newdiv
{
width:800px;
height:800px;
border:1px solid #000;
}
.table
{
position:absolute;
margin-top:100px;
margin-left:20px;
}
</style>
<script>
function changeimage(image)
{
if (image.cc==0)
{
image.cc=1;
$(image).attr('src', 'images/white_contact.png');
}
else if (image.cc==1)
{
image.cc=2;
$(image).attr('src', 'images/yellow_contact.png');
}
else if (image.cc==2)
{
image.cc=3;
$(image).attr('src', 'images/green_contact.png');
}
else
{
image.cc=0;
$(image).attr('src', 'images/red_contact.png');
}
}
</script>
<script type="text/javascript" language="javascript">
var i=0;
function createDiv()
{
if(i < 6) {
$('#newdiv').append('<div id="div"'+i+'" class="ex" style="text-align: left;"><div id="div"'+i+'" class= "square"><table border="0" class = "table" ><tr><td width="51">Name:</td><td width="141"><input type="text" size="10" class = "name"></td></tr><tr><td>Title:</td><td><input type="text" size="10" class = "title"></td></tr><tr><td>Contact:</td><td><input type="text" size="10" class = "contact"></td></tr></table></div><img class="myimage" ondblclick="changeimage(this)" border="0"src="http://forums.hardwarezone.com.sg/images/white_contact.png" width="60" /></div>');
}
$.ajax({
url: 'savecontact.php',
type: 'POST',
success:function (data) {
if (data == '1')
{
$("#star")
.html("Data saved successfully")
}
else
{
$("#star")
.html("error")
}
}
});
i++;
$( ".ex" ).draggable({containment:'parent',cursor:'pointer',opacity:0.6});
$( ".ex" ).droppable();
}
</script>
</head>
<body>
<p align="left">
<b>Click this button to create div element dynamically:</b>
<input id="btn1" type="button" value="create div" onClick="createDiv();" />
<div id = "star"></div>
<div id = "newdiv">
</div>
</p>
</body>
</html>
I want to insert 6 empty record into my contact table while I click on the same button 6 times instantly, so it is like, I click on the button 5 times, 5 record is inserted. I am using Ajax
this is my PHP file for SQL query, savecontact.php
Code:
<?php
include('config.php') ;
$sql = "INSERT into contact(FirstName,LastName,Email,OfficePhone,MobilePhone, Position, Department, CustomerID, CreatedBy, DateCreated)values ('', '' , '', '', '', '', '','','','')";
if (mysql_query($sql))
{
echo 1;
}
?>
I not sure what wrong, now I can create 6 new record, ONLY IF I click one by one SLOWLY, if I click 6 times on the button, only 4 records is inserted, or when I am slower, I can created 5 records
Is it Insert new record need time?