Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > JavaScript Dynamic อยากได้ Textbox CreateElement แบบเพิ่มได้ที่ไม่เป็น Array



 

JavaScript Dynamic อยากได้ Textbox CreateElement แบบเพิ่มได้ที่ไม่เป็น Array

 



Topic : 044751

Guest




อยากได้ textbox แบบเพิ่มได้ที่ไม่เป็น array



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-06-30 18:21:43 By : san View : 8394 Reply : 14
 

 

No. 1



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


ตั้งชื่อให้ต่างกันด้วยจำนวนที่เพิ่ม แล้วส่ง hidden field ไปด้วยว่าเพิ่มไปเท่าไหร่แล้วหน้ารับก็วนลูปเอาตามจำนวนที่ส่ง คงไม่งงนะ อยากได้ของแปลกก็ต้องทำใจ






Date : 2010-06-30 19:10:06 By : plakrim
 


 

No. 2

Guest


มีโค้ดให้ดูไหม
Date : 2010-06-30 20:31:06 By : TOON
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code (PHP)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<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>
<body>
	<form action="php_multiple_upload5.php" method="post" name="form1" enctype="multipart/form-data">
		<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>
</body>
</html>


อันนี้เป็น name ครับ ไม่ได้เป็น Array
Date : 2010-06-30 20:53:58 By : webmaster
 


 

No. 4



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

การอ่านค่า

Code (PHP)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
	<?
		mysql_connect("localhost","root","root") or die (mysql_error());
		mysql_select_db("mydatabase");

		for($i=1;$i<=(int)($_POST["hdnLine"]);$i++)
		{
			if($_FILES["fileUpload".$i]["name"] != "")
			{
				if(copy($_FILES["fileUpload".$i]["tmp_name"],"shotdev/".$_FILES["fileUpload".$i]["name"]))
				{
					$strSQL = "INSERT INTO gallery ";
					$strSQL .="(GalleryName,Picture) VALUES ('".$_POST["txtGalleryName".$i]."','".$_FILES["fileUpload".$i]["name"]."')";
					mysql_query($strSQL);
					echo "Copy/Upload ".$_FILES["fileUpload".$i]["name"]." completed.<br>";
				}
			}
		}

		echo "<br><a href='php_multiple_upload6.php'>View file</a>";

		mysql_close();
	?>
</body>
</html>

Date : 2010-06-30 20:56:04 By : webmaster
 


 

No. 5



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


นั่นไง ตามนั้น พี่วินจัดไป
Date : 2010-06-30 22:21:12 By : plakrim
 


 

No. 6

Guest


ขอโค้ดให้ครบหน่อยสิ ขอบคุณครับ
Date : 2010-07-01 07:59:58 By : TOON
 


 

No. 7



โพสกระทู้ ( 1,268 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Blogger

พี่เค้าให้มาครบเลยนะเนี่ย ตั้งแค่ <html> จนถึง </html> เชียวนะคะ
Date : 2010-07-01 08:37:37 By : ultrasiam
 


 

No. 8

Guest


อยากได้ต้อง View file ด้วยอะมีไหมครับ
Date : 2010-07-01 08:47:16 By : san
 


 

No. 9



โพสกระทู้ ( 139 )
บทความ ( 0 )



สถานะออฟไลน์


php_multiple_upload6.php

มีไฟล์นี้เปล่าครับ
Date : 2010-07-07 21:31:23 By : satonpanit
 


 

No. 10



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

อันนี้เพิ่มภายใต้ table ครับ

วันนี้ใจดีเขียนให้อีกแล้วครับ


Code (JavaScript)
<html>
<head>
<title>ThaiCreate.Com JavaScript Add/Remove Element</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<script language="javascript">
	function CreateNewRow()
	{
		var intLine = parseInt(document.frmMain.hdnMaxLine.value);
		intLine++;
			
		var theTable = document.all.tbExp
		var newRow = theTable.insertRow(theTable.rows.length)
		newRow.id = newRow.uniqueID
		
		var item1 = 1
		var newCell
		
		//*** Column 1 ***//
		newCell = newRow.insertCell(0)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column1_"+intLine+"\" VALUE=\"\"></center>"

		//*** Column 2 ***//
		newCell = newRow.insertCell(1)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column2_"+intLine+"\" VALUE=\"\"></center>"		
		
		//*** Column 3 ***//
		newCell = newRow.insertCell(2)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column3_"+intLine+"\" VALUE=\"\"></center>"				
		
		//*** Column 4 ***//
		newCell = newRow.insertCell(3)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column4_"+intLine+"\" VALUE=\"\"></center>"		
		
		//*** Column 5 ***//
		newCell = newRow.insertCell(4)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column5_"+intLine+"\" VALUE=\"\"></center>"			
		
		document.frmMain.hdnMaxLine.value = intLine;
	}
	
	function RemoveRow()
	{
		intLine = parseInt(document.frmMain.hdnMaxLine.value);
		if(parseInt(intLine) > 0)
		{
				theTable = (document.all) ? document.all.tbExp : 
				document.getElementById("tbExp")
				theTableBody = theTable.tBodies[0];
				theTableBody.deleteRow(intLine);
				intLine--;
				document.frmMain.hdnMaxLine.value = intLine;
		}	
	}	
</script>
<body>
<form name="frmMain" method="post">
<table width="445" border="1" id="tbExp">
  <tr>
    <td><div align="center">Column 1 </div></td>
    <td><div align="center">Column 2 </div></td>
    <td><div align="center">Column 3 </div></td>
    <td><div align="center">Column 4 </div></td>
    <td><div align="center">Column 5 </div></td>
  </tr>
</table>
<input type="hidden" name="hdnMaxLine" value="0">
<input name="btnAdd" type="button" id="btnAdd" value="+" onClick="CreateNewRow();">
<input name="btnDel" type="button" id="btnDel" value="-" onClick="RemoveRow();">
</form>
</body>
</html>


Screenshot


JavaScript Add/Remove Element




อันนี้ CreateElement Multiple Input File Upload แบบไม่ใช้ Array ครับ

Go to : PHP MySQL Upload File to MySQL - Multiple Dynamic CreateElement Input File Upload
Date : 2010-09-14 10:59:57 By : webmaster
 


 

No. 11



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

กำหนดค่า Default Rows ครับ

Code
<body Onload="CreateNewRow();CreateNewRow();CreateNewRow();">


ง่าย ๆ ครับ จะใส่กี่แถวก็ใส่ไปครับ

Code (JavaScript)
<html>
<head>
<title>ThaiCreate.Com JavaScript Add/Remove Element</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<script language="javascript">
	function CreateNewRow()
	{
		var intLine = parseInt(document.frmMain.hdnMaxLine.value);
		intLine++;
			
		var theTable = document.all.tbExp
		var newRow = theTable.insertRow(theTable.rows.length)
		newRow.id = newRow.uniqueID
		
		var item1 = 1
		var newCell
		
		//*** Column 1 ***//
		newCell = newRow.insertCell(0)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column1_"+intLine+"\" VALUE=\"\"></center>"

		//*** Column 2 ***//
		newCell = newRow.insertCell(1)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column2_"+intLine+"\" VALUE=\"\"></center>"		
		
		//*** Column 3 ***//
		newCell = newRow.insertCell(2)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column3_"+intLine+"\" VALUE=\"\"></center>"				
		
		//*** Column 4 ***//
		newCell = newRow.insertCell(3)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column4_"+intLine+"\" VALUE=\"\"></center>"		
		
		//*** Column 5 ***//
		newCell = newRow.insertCell(4)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column5_"+intLine+"\" VALUE=\"\"></center>"			
		
		document.frmMain.hdnMaxLine.value = intLine;
	}
	
	function RemoveRow()
	{
		intLine = parseInt(document.frmMain.hdnMaxLine.value);
		if(parseInt(intLine) > 0)
		{
				theTable = (document.all) ? document.all.tbExp : 
				document.getElementById("tbExp")
				theTableBody = theTable.tBodies[0];
				theTableBody.deleteRow(intLine);
				intLine--;
				document.frmMain.hdnMaxLine.value = intLine;
		}	
	}	
</script>
<body Onload="CreateNewRow();CreateNewRow();CreateNewRow();">
<form name="frmMain" method="post">
<table width="445" border="1" id="tbExp">
  <tr>
    <td><div align="center">Column 1 </div></td>
    <td><div align="center">Column 2 </div></td>
    <td><div align="center">Column 3 </div></td>
    <td><div align="center">Column 4 </div></td>
    <td><div align="center">Column 5 </div></td>
  </tr>
</table>
<input type="hidden" name="hdnMaxLine" value="0">
<input name="btnAdd" type="button" id="btnAdd" value="+" onClick="CreateNewRow();">
<input name="btnDel" type="button" id="btnDel" value="-" onClick="RemoveRow();">
</form>
</body>
</html>


Screenshot

Ajax Auto Create Element
Date : 2011-04-07 21:28:48 By : webmaster
 


 

No. 12



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

กรณีต้องการ Validate หรือตรวจสอบค่าว่าง ครับ

Go to : การใช้ JavaScript CreateElement and Validate ตรวจสอบค่า Rows , Column ตรวจสอบค่าว่าง
Date : 2011-04-12 16:50:18 By : webmaster
 


 

No. 13



โพสกระทู้ ( 14 )
บทความ ( 0 )



สถานะออฟไลน์


Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>addtrm</title>
<script type="text/javascript">
function addFile(theBtn){
  var theForm = theBtn.form;
  if(theForm.fileCount.value>=50) return;
  var fileNum = theForm.fileCount.value -= -1;
  var theDiv = theForm.userfile1;
	if(theDiv.length) theDiv = theDiv[0];
  theDiv = theDiv.parentNode;
  var newDiv = theDiv.cloneNode(true);
  var newFile = newDiv.getElementsByTagName("input")[0];
  newFile.name = "userfile"+fileNum;
  newFile.id = newFile.name;
  theBtn.parentNode.insertBefore(newDiv, theBtn)
}
</script>
</head>

<body>

<form id="Form1" name="Form1" method="post" action="">
  <input type=hidden name="fileCount" value="1">
  <div align = center><input type=text name="userfile1" size ="40"  ></div>
  
  <table width="108" border="0" align="center" cellpadding="1" cellspacing="1">
    <tr>
      <td align="center"><button  onClick="addFile(this)" type=button><img src="../icon/add.png"   width="104" height="87" border="0" alt="" /></button ></td>
    </tr>
  </table>
  </form>


</body>
</html>


ลองดูครับ แบบนี้หรือปล่าว แต่ของผมมันยังลบไม่ได้นะ เพิ่มได้อย่างเดียว
Date : 2011-04-20 16:02:06 By : tonglar
 


 

No. 14



โพสกระทู้ ( 139 )
บทความ ( 0 )



สถานะออฟไลน์


อยากเพิ่มแค่ 5 อันทำงัยครับพี่วิน
Date : 2012-01-19 16:25:57 By : satonpanit
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : JavaScript Dynamic อยากได้ Textbox CreateElement แบบเพิ่มได้ที่ไม่เป็น Array
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่