|
|
|
javascript กด เพิ่ม Form ละไม่มีอะไรเกิดขึ้นไม่Error นิ่งเลยอะครับ เกิดจากสาเหตุอะไรได้บ้างครับ |
|
|
|
|
|
|
|
ส่วนของ Java ที่เพิ่ม form
Code (JavaScript)
<script language="javascript">
function fncCreateElement(){
var mySpan = document.getElementById('mySpan');
var myLine = document.getElementById('hdnLine');
myLine.value++;
// Create input text
var myElement1 = document.createElement('input');
myElement1.setAttribute('type',"text");
myElement1.setAttribute('name',"txtGalleryName"+myLine.value);
myElement1.setAttribute('id',"txt"+myLine.value);
mySpan.appendChild(myElement1);
// Create input file
var myElement2 = document.createElement('input');
myElement2.setAttribute('type',"file");
myElement2.setAttribute('name',"fileUpload"+myLine.value);
myElement2.setAttribute('id',"fil"+myLine.value);
mySpan.appendChild(myElement2);
// Create <br>
var myElement3 = document.createElement('<br>');
myElement3.setAttribute('id',"br"+myLine.value);
mySpan.appendChild(myElement3);
}
function fncDeleteElement(){
var mySpan = document.getElementById('mySpan');
var myLine = document.getElementById('hdnLine');
if(myLine.value > 1 )
{
// Remove input text
var deleteFile = document.getElementById("txt"+myLine.value);
mySpan.removeChild(deleteFile);
// Remove input file
var deleteFile = document.getElementById("fil"+myLine.value);
mySpan.removeChild(deleteFile);
// Remove <br>
var deleteBr = document.getElementById("br"+myLine.value);
mySpan.removeChild(deleteBr);
myLine.value--;
}
}
</script>
ส่วนของ Form
Code (PHP)
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("dormitory");
mysql_query("SET NAMES UTF8");
$DormitoryID = $_REQUEST['addpic'];
$strSQL = "SELECT * FROM gallery ";
$result_show = mysql_query($strSQL) or die(mysql_error());
$objResult= mysql_fetch_array($result_show);
?>
<form action="check_uploadpic.php" method="post" name="form1" enctype="multipart/form-data">
<input type="hidden" name="addpicID" value="<?php echo $DormitoryID;?>">
<input type="text" name="txtGalleryName1"><input type="file" name="fileUpload1">
<input name="btnCreate" type="button" value="+" onClick="JavaScript:fncCreateElement();">
<input name="btnDelete" type="button" value="-" onClick="JavaScript:fncDeleteElement();"><br>
<span id="mySpan"></span>
<input name="hdnLine" type="hidden" value="1">
<input name="btnSubmit" type="submit" value="Submit">
</form>
Tag : PHP, JavaScript
|
|
|
|
|
|
Date :
2016-06-22 23:49:07 |
By :
mylastgame |
View :
693 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<input name="hdnLine" id="hdnLine" type="hidden" value="1">
เพิ่มสีแดง
หรือ
var myLine = document.getElementById('hdnLine');
แก้เป็น
var myLine = document.getElementsByName('hdnLine').item(0);
ปล.อันนี้ด้วย
var myElement3 = document.createElement('<br>');
แก้เป็น
var myElement3 = document.createElement('br');
|
ประวัติการแก้ไข 2016-06-23 07:26:15
|
|
|
|
Date :
2016-06-23 07:21:23 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(document).ready(function(e) {
var span=$('span');
$('#btnP').on('click',function(){
var Element="<input type='text' name='txt[]'>";
span.append(Element);
});
$('#btnD').on('click',function(){
span.find('input').last().remove();
});
});
</script>
<button id="btnP">Plus</button><button id="btnD">Delete</button>
<span></span>
|
|
|
|
|
Date :
2016-06-23 09:31:44 |
By :
dudesaranyu |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|