Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/08/2011, 11:35
kvnkain
 
Fecha de Ingreso: agosto-2011
Mensajes: 1
Antigüedad: 12 años, 8 meses
Puntos: 0
Pregunta No se que pasa en el codigo, se desabilita el codigo

Buenas! quiero tratar de funcionar un codigo q hecho, se trata de aser un work order con la opciones de agregar mas ordenes y eliminar ordenes, y despues enviarlos a un php que prosesara los datos de las cajas y los enviara a un correo converitdo en pdf, ok el detalle es en el codigo del formulario funciona la opcion de agregar y elminar pero deja de funcionar la suma y la multiplicaciones aki le pongo los codigos

(HTML)
Código:
<script type='text/javascript' src='js/jquery-1.3.2.min.js'></script>
<script type='text/javascript' src='js/kevinsummul.js'></script>
<script type="text/javascript">


</script>

<div id="order-detail-content" class="table_block">
  <table id="cart_summary" class="std">
    <thead>
      <tr>
        <th width="87" class="cart_product first_item">Product</th>
        <th width="102" class="cart_description item">Description</th>
        <th width="72" class="cart_quantity item">Unit Cost</th>
        <th width="72" class="cart_quantity item">Qty</th>
        <th width="56" class="cart_total last_item">Total</th>
      </tr>
    </thead>
    <tfoot>
      <tr class="cart_total_price">
        <td colspan="4"></td>
        <td width="58"  id="total_product"></td>
      </tr>
      <tr class="cart_total_delivery">
        <td colspan="4">Subtotal</td>
        <td width="58" class="total-value" id="total_product"><textarea style="display:none;" id="paid">$0.00</textarea>
        <spam id="subtotal">$0.00</spam></td>
      </tr>
      <tr class="cart_total_price">
        <td colspan="4">Total</td>
        <td width="58" class="total-value" id="total_product"><textarea style="display:none;" cols="8" rows="1" readonly="readonly" id="total"></textarea>
          <div class="due">$0.00</div></td>
      </tr>
      <tr class="cart_total_voucher" style="display: none;"> </tr>
    </tfoot>
    <tbody>
      
    </tbody>
  </table>

  <p><input type='button' value='Add Button' id='addButton'>
<input type='button' value='Remove Button' id='removeButton'>
&nbsp;</p>
</div>
JAVASCRIPT/JQUERY
Código:
function print_today() {
  // ***********************************************
  // AUTHOR: WWW.CGISCRIPT.NET, LLC
  // URL: http://www.cgiscript.net
  // Use the script, just leave this message intact.
  // Download your FREE CGI/Perl Scripts today!
  // ( http://www.cgiscript.net/scripts.htm )
  // ***********************************************
  var now = new Date();
  var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
  var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
  function fourdigits(number) {
    return (number < 1000) ? number + 1900 : number;
  }
  var today =  months[now.getMonth()] + " " + date + ", " + (fourdigits(now.getYear()));
  return today;
}

// from http://www.mediacollege.com/internet/javascript/number/round.html
function roundNumber(number,decimals) {
  var newString;// The new rounded number
  decimals = Number(decimals);
  if (decimals < 1) {
    newString = (Math.round(number)).toString();
  } else {
    var numString = number.toString();
    if (numString.lastIndexOf(".") == -1) {// If there is no decimal point
      numString += ".";// give it one at the end
    }
    var cutoff = numString.lastIndexOf(".") + decimals;// The point at which to truncate the number
    var d1 = Number(numString.substring(cutoff,cutoff+1));// The value of the last decimal place that we'll end up with
    var d2 = Number(numString.substring(cutoff+1,cutoff+2));// The next decimal, after the last one we want
    if (d2 >= 5) {// Do we need to round up at all? If not, the string will just be truncated
      if (d1 == 9 && cutoff > 0) {// If the last digit is 9, find a new cutoff point
        while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {
          if (d1 != ".") {
            cutoff -= 1;
            d1 = Number(numString.substring(cutoff,cutoff+1));
          } else {
            cutoff -= 1;
          }
        }
      }
      d1 += 1;
    } 
    if (d1 == 10) {
      numString = numString.substring(0, numString.lastIndexOf("."));
      var roundedNum = Number(numString) + 1;
      newString = roundedNum.toString() + '.';
    } else {
      newString = numString.substring(0,cutoff) + d1.toString();
    }
  }
  if (newString.lastIndexOf(".") == -1) {// Do this again, to the new string
    newString += ".";
  }
  var decs = (newString.substring(newString.lastIndexOf(".")+1)).length;
  for(var i=0;i<decimals-decs;i++) newString += "0";
  //var newNumber = Number(newString);// make it a number if you like
  return newString; // Output the result to the form field (change for your purposes)
}

function update_total() {
  var total = 0;
  $('.price').each(function(i){
    price = $(this).html().replace("$","");
    if (!isNaN(price)) total += Number(price);
  });

  total = roundNumber(total,2);

  $('#subtotal').html("$"+total);
  $('#total').html("$"+total);
  
  update_balance();
}

function update_balance() {
  var due = $("#total").html().replace("$","") - $("#paid").val().replace("$","");
  due = roundNumber(due,2);
  
  $('.due').html("$"+due);
}

function update_price() {
  var row = $(this).parents('.item-row');
  var price = row.find('.cost').val().replace("$","") * row.find('.qty').val();
  price = roundNumber(price,2);
  isNaN(price) ? row.find('.price').html("N/A") : row.find('.price').html("$"+price);
  
  update_total();
}

function bind() {
  $(".cost").blur(update_price);
  $(".qty").blur(update_price);
}

   $(document).ready(function(){
  bind();

	    var counter = 1;
		
	    $("#addButton").click(function () {
				
			if(counter>10){
		        return false;
		    }   
			
			var newTextBoxDiv = $(document.createElement('tr')).attr("id", 'TextBoxDiv' + counter).attr("class", 'item-row');
                newTextBoxDiv.after().html('<td  class="cart_product"><select name="combo'+ counter + '" onChange="cambio(this.value)">' +
				'<option value="0" selected>ITEM</option><option value="baleares">Baleares</option><option value="catalunya">Cataluña</option><option value="galicia">Galicia</option></select></td><td  class="cart_quantity"><input size="45" type="text"  name="sss'+ counter + 
				'" readonly="readonly" /></td>' + counter + 	
				'<td  class="cart_quantity"><input size="2" type="text"  value="1"  name="cost'+ counter + 
				'" class="cost" /></td>'
				 + counter + 
				'<td  class="cart_quantity"><input size="2" type="text"  value="1"  name="qty'+ counter + 
				'" class="qty" /></td>'
				 + counter +
				'<td  class="cart_total"><span  class="price" id="total_product_price_28_0">$0.00</span></td>');
            
			newTextBoxDiv.appendTo("tbody");
				
		    counter++;
	    });

	    $("#removeButton").click(function () {
		    if(counter==1){
		        alert("No more textbox to remove");
		        return false;
		    }   
	        counter--;
			
	        $("#TextBoxDiv" + counter).remove();
		});
		
				
  });
el problema como dije arriba cuando agrego la tabla no funciona las funciones de sumar y multiplicar etc porfavor revisen mi codigo y diganme q es lo malo y como lo puedo optimisar gracias :D