<script language="javascript">

function add()
{

		var divTag = document.createElement("div");
       	divTag.id = "div";
		//alert(divTag.id);
       
        //divTag.setAttribute("align","center");
       
        //divTag.style.margin = "0px auto";
       
        divTag.className ="dynamicDiv";
var v1 =document.getElementById('ttlBoxes').value;
var v2 =document.getElementById('boxno[]').value;

var d1=parseInt(document.getElementById('ttlBoxes').value);
var d2=parseInt(document.getElementById('boxno[]').value);
if(v1!=""&& v2!="")
{
if(d2<d1)
{
       
divTag.innerHTML ='<br /><table width="101%" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable" ><tr ><td  width="150" class="label" ><select id="boxtype[]" name="boxtype[]" ><option value="select">Select</option><option value="Amb">Amb</option><option value="Frz">Frz</option><option value="Ref">Ref</option><option value="Gen">Gen</option></select>&nbsp;&nbsp;&nbsp;&nbsp;<select id="box[]" name="box[]"><option value="select" >Select</option><option value="OurBox">Our Box</option><option value="DrBox">Dr.Box</option><option value="Other">Other</option></select>GrossWeight<input type="text" name="grWeight[]"  id="grWeight[]" value="0"  onclick="calc(this)" readonly="readonly" /></td><td width="150" class="label" ><p>Box Nos.<input name="boxno[]" type="text" class="box" id="boxno[]" size="20" maxlength="255" value=""  /></p><p>ChargebleWeight<input type="text" name="crWeight[]"  id="crWeight[]" value="" /></p></td><td class="label" ><p>Dimension<input name="l[]" type="text" class="box" id="l[]" size="3" maxlength="255" value="" />x<input name="b[]" type="text" class="box" id="b[]" size="3" maxlength="255" value=""  />x<input name="h[]" type="text" class="box" id="h[]" size="3" maxlength="255" value="" /></p>  <input type="button" value="Add" onClick="add(this)"></td></tr></table>';
       
document.getElementById("my_div").appendChild(divTag);
		
}
else if (d2==d1)
{
alert("Box No. has reached max limit");
}
else if(d2>d1)
{
alert("OOps more than total numbers ");
}
}
else
{
alert("Please enter total Box/Box nos .");
}
}

</script>



<script type="text/javascript"> 
function calc(){ 
if ( isNaN(document.getElementById("l[]").value) == true )
{
alert('The  value is not numeric');
document.getElementById("l[]").value.focus();
document.getElementById("l[]").value.select();
return false;
}
if ( isNaN(document.getElementById("b[]").value) == true )
{
alert('The  value is not numeric');
document.getElementById("b[]").value.focus();
document.getElementById("b[]").value.select();
return false;
} 
if ( isNaN(document.getElementById("h[]").value) == true )
{
alert('The  value is not numeric');
document.getElementById("h[]").value.focus();
document.getElementById("h[]").value.select();
return false;
}
if ( isNaN(document.getElementById("boxno[]").value) == true )
{
alert('The  value is not numeric');
document.getElementById("boxno[]").value.focus();
document.getElementById("boxno[]").value.select();
return false;
}

   var l1 =parseFloat(document.getElementById("l[]").value);
  var b1 =parseFloat(document.getElementById("b[]").value);
  var h1 =parseFloat(document.getElementById("h[]").value);
  var box = parseFloat(document.getElementById("boxno[]").value);
 
     var r =(l1*b1*h1/6000)*box; 
     ( document.getElementById("grWeight[]").value) = r; 
     
} 
</script> 

<form action="processExport.php?action=add" method="post" enctype="multipart/form-data" name="frmAddUser" id="frmAddUser">
 <table width="101%" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable">

 <tr>
    <td width="169" class="label">Total Boxes</td>
    <td colspan="3" class="content"><input name="ttlBoxes" type="text" class="box" id="ttlBoxes" size="20" maxlength="255"  
    value="" />    </td>
  </tr>
  <tr id=myrow > 
     <td class="label">Box</td>
     <td class="label">
  <select id="boxtype[]" name="boxtype[]">
    <option value="select">Select</option>
     <option value="Amb">Amb</option>
     <option value="Frz">Frz</option>
     <option value="Ref">Ref</option>
     <option value="Gen">Gen</option>
  </select>&nbsp;&nbsp;&nbsp;&nbsp;
       <select id="box" name="box">
         <option value="select">Select</option>
         <option value="OurBox">Our Box</option>
         <option value="DrBox">Dr.Box</option>
         <option value="Other">Other</option>
       </select>          
     &nbsp;&nbsp;&nbsp;&nbsp;Gross Weight  
        <input type="text" name="grWeight[]"  id="grWeight[]" value="0"  onclick="calc(this)"  readonly="readonly"/></td>   		 
	  <td  class="label"><p>Box Nos.
	    <input name="boxno[]" type="text" class="box" id="boxno[]" size="20" maxlength="255" value=""  
     />
	  </p>
	    <p>Chargeble Weight
	      <input type="text" name="crWeight[]"  id="crWeight[]" value=""  />
</p></td> 		
     <td class="label">
       <p>Dimension
         <input name="l[]" type="text" class="box" id="l[]" size="3" maxlength="255" 
     value="" />
         x
         <input name="b[]" type="text" class="box" id="b[]" size="3" maxlength="255" 
     value="" />
         x
         <input name="h[]" type="text" class="box" id="h[]" size="3" maxlength="255" 
     value="" />
       </p>
       <p>
        <input type="button" value="Add" onClick="add()">
       </p></td>
   </tr>   
   <tr>
   <td class="label"></td>
   <td class="label" colspan="3">  
 <div id="my_div" name="my_div">

</div></td>   
   </tr>
</table>
</form>

In above code there is <tr id=myrow > in which calculation part of field box no. ,l,b,h
which is done by javascript.but problem is that the javascript function operate only first time ,but after adding this <tr >again ,then javascript is not working .
please give me solution on that problem .

If there is any other way to doing this task plese tell me.

Member Avatar for diafol

This is javascript, post it in the js forum. This is for php.

Thread closed as there is already double in JavaScript section. Please follow discussion here

@ardav it is better to just mark thread for mods attention instead of advising to post it in other section. Those we avoid double posts. Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.