|  | 
	                
  
    | 
	 
        อยากให้ เอาข้อมูลเกี่ยวกับ u_phone pavlue และ total_phone ออก และเพิ่ม textbox ชื่อ total_room รับค่าจากฐานข้อมูล     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | คือ  scrip  ตัวนี้การทำงานคือ รับค่า pvalue กับ  u_phoneคูณกัน  ผล ใส่ใน total_phone
 รับค่า wvalue  กัย u_water คูณกัน  ผลใส่ใน total_water
 รับค่า fvalue  กับ u_fire คูณกัน  ผลใส่ใน total_fire
 แล้วค่าของ total_phone total_water  total_fire บวกกัน  ผลใส่ใน  be_total
 
 ***   อยากให้ เอาข้อมูลเกี่ยวกับ  u_phone   pavlue  และ total_phone  ออก  และเพิ่ม  textbox ชื่อ total_room  รับค่าจากฐานข้อมูล $value_room
 
 แล้วเอาค่ามาบวกกับ  total_water   total_fire   ผลลัพธ์ใส่ใน  be_total  นะค่ะ  คือลองเอาออกแล้วมันไม่ยอมบวกกันนะค่ะ
 
 code
 
 
<script type="text/javascript">
	    function addCommas(nStr) {
        nStr += '';
        x = nStr.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
    }
    //*define object "Bill"
    function Bill(){
        //get form value
        var unit = {
            'water' : document.form2.wvalue.value,
            'fire' : document.form2.fvalue.value,
            'phone' : document.form2.pvalue.value
		
        }
        var rate = {
            'water' : document.form2.u_water.value,
            'fire' : document.form2.u_fire.value,
            'phone' : document.form2.u_phone.value
        }
        //private function
        this.calc = function(unit, rate){
            unit = parseFloat(unit);
            rate = parseFloat(rate);
            if(!unit || !rate){return 0;}
            return unit * rate;
        }
        //public properties
        this.water = this.calc(unit['water'],rate['water']);
        this.fire = this.calc(unit['fire'],rate['fire']);
        this.phone = this.calc(unit['phone'],rate['phone']);
    }
    function calcBill(){
        var bill = new Bill();
        document.form2.total_water.value = addCommas(bill.water.toFixed(2));
        document.form2.total_fire.value = addCommas(bill.fire.toFixed(2));
        document.form2.total_phone.value = addCommas(bill.phone.toFixed(2));
        document.form2.be_total.value = addCommas((bill.water + bill.fire + bill.phone).toFixed(2));
    }
</script>
 
 
 Tag : - - - -
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2009-10-25 20:12:32 | By :
                          ***_*** | View :
                          843 | Reply :
                          5 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | มีใครอยู่ไหม 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-10-25 22:42:56 | By :
                            aung |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | <script type="text/javascript">
	    function addCommas(nStr) {
        nStr += '';
        x = nStr.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
    }
    //*define object "Bill"
    function Bill(){
        //get form value
        var unit = {
            'water' : document.form2.wvalue.value,
            'fire' : document.form2.fvalue.value
        }
        var rate = {
            'water' : document.form2.u_water.value,
            'fire' : document.form2.u_fire.value
        }
        //private function
        this.calc = function(unit, rate){
            unit = parseFloat(unit);
            rate = parseFloat(rate);
            if(!unit || !rate){return 0;}
            return unit * rate;
        }
        //public properties
        this.water = this.calc(unit['water'],rate['water']);
        this.fire = this.calc(unit['fire'],rate['fire']);
    }
    function calcBill(){
        var bill = new Bill();
        document.form2.total_water.value = addCommas(bill.water.toFixed(2));
        document.form2.total_fire.value = addCommas(bill.fire.toFixed(2));
        document.form2.be_total.value = addCommas((bill.water + bill.fire + document.form2.total_room.value*1).toFixed(2));
    }
</script>
<form name="form2">
	<br />wvalue<input name="wvalue" value="10" />
	<br />fvalue<input name="fvalue" value="20" />
	
	<br />uwater<input name="u_water" value="3" />
	<br />ufire<input name="u_fire" value="2" />
	<br />total water<input name="total_water" />
	<br />total fire<input name="total_fire" />
	<?php $value_room = 100; ?>
	<br />total room<input name="total_room" value="<?php echo (int)$value_room;?>" />
	
	<br /><input name="be_total" />	
	<br /><input type="button" value="cal" onclick="calcBill();" />
</form>
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-10-25 23:53:07 | By :
                            num |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | เพ่หนุ่มยังอยู่ สวัสดียามดึกๆ ดื่นๆ ครับเพ่หนุ่ม หลับฝันดีนะครับ นอนล่ะ 
     
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-10-26 01:13:43 | By :
                            NanoThoro |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ถ้าอยากให้แสดงผลเลยโดยไม่ต้องกด  submit  ละค่ะ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-10-26 06:29:21 | By :
                            aung |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | คือ  ค่าจากฐานข้อมูล total_room มันเป็น  3,000.00  นะค่ะ  ตอนนี้  มันแสดงค่า  เท่ากับ 3  นะค่ะ  แก้ยังไงค่ะ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-10-26 06:39:10 | By :
                            aung |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |