You are here: Home » JavaScript » Add more in PHP

Add more in PHP

45 Flares 45 Flares ×

To use add more in php, we have to create a function addlinks(), in this function we define field which we have to call on alllinks() function, here we call a test field with name all_part, define it in array.

Also, call a function removelinks() to remove added link.

Just create a php page and paste below code, You may change or add field in newdivlink.innerHTML .

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
function addlinks(name) {
  var i = name.replace("addMore", "");
  var ni = document.getElementById('myDivlink');
  var numi = document.getElementById('thelink');
  var numlink = (document.getElementById('thelink').value -1)+ 2;
  numi.value = numlink;
  var newdivlink = document.createElement('div');
  var divIdName = 'my'+numlink+'Divlink';
				 newdivlink.innerHTML = '<div style=" clear:both; overflow:hidden;"><span style="width:160px; display:block; float:left;" ><input type="text" name="all_part[]" id="fname"  size="32" style="width:145px; display:block; margin:21px 0 0 0px; float:left; height:15px;"></span><span id="ad.dMore'+numlink+'" style="width:21px; display:block; float:left;"><a href="javascript:void(0)" onclick="javscript:removelinks(\''+numlink+'\');" style="margin:13px 0 0 8px; float:left;"><img src="b_drop.gif" alt="Delete"  /></a></span><span style="width:75px; display:block; float:left;">&nbsp;</span></div>';

function removelinks(divNumlink) { 
  var  b ="my"+divNumlink+"Divlink";
  var d = document.getElementById('myDivlink');
  var olddiv = document.getElementById(b);
  return false;


 <div style="width:400px;">
                             <? $k =0; ?>
                      <span id="myDivlink" style="margin-bottom:5px;">
                    <? $k =0; ?>
                      <div id="my<?php echo $k;?>Divlink" style="margin-bottom:5px;">
						 <input type="hidden" name="thelink" id="thelink" value="1">
                         <span id="addMore<?php echo $k;?>"  style="float:right; "><?php
						 ?><a href="javascript:void(0)" onClick="javscript:addlinks('addMore<?php echo $k;?>');" style="margin-left:10px;">Add More</a><?php
						  <br />

About Abhishek Sinha

I am Abhishek and I love to code on PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *


Scroll To Top
45 Flares Twitter 4 Facebook 12 Google+ 20 StumbleUpon 5 Pin It Share 0 LinkedIn 4 45 Flares ×