ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => ข้อความที่เริ่มโดย: mija ที่ 16 มิถุนายน 2010, 07:32:58



หัวข้อ: สคริปไม่ทำงาน วานผู้รู้ช่วยชี้แนะด้วยค่ะ
เริ่มหัวข้อโดย: mija ที่ 16 มิถุนายน 2010, 07:32:58
อ้างถึง
<script type="text/javascript" language="javascript">
         function calculate()
         {
            var productPrice =  document.getElementById('productPrice').value;
            var shipPrice  = document.getElementById('shipPrice').value;
            var totalPrice = document.getElementById('totalPrice');
            var calculateToThai = document.getElementById('calculateToThai');
            totalPrice.value = parseInt(productPrice)   parseInt(shipPrice);
            calculateToThai.value = parseInt(totalPrice.value) * 36;
            var fee = document.getElementById('fee').value;
            calculateToCost.value = parseInt(totalPrice1.value) * 5;
            var fe1e = document.getElementById('fee1').value;
            calculateToCost.value = parseInt(totalPrice2.value) * 5;
            totalPrice2.value = parseInt(fee)   parseInt(fee1);
   
         }
      </script>ค่าสินค้า
          <input type="text" id="productPrice"/>
  $<br/>
      ค่าขนส่งสินค้า 
       <input type="text" id="shipPrice"/>
      $<br/>
      คิดเป็นเงิน 
       <input type="text" id="totalPrice"/>
      $<br/>
      คิดเป็นเงินไทย
      <input type="text" id="calculateToThai"/>
      บาท
        <br/>
        บวกค่าธรรมเนียมธนาคารออนไลน์ 5%
        <br/>
        บวกค่าธรรมเนียมบัตรเครดิต 5%
 
<br/>
      ค่าใช้จ่ายทั้งสิ้นรวม <input type="text" id="toTalPrice2"/>
 
<br/>
      <input type="submit" value="Calculate" onClick="calculate()"/>

พยายามหันเขียนเองอยู่ แต่มันคำนวนแค่ช่วงแรก  :'( รบกวนด้วยนะคะ


หัวข้อ: Re: สคริปไม่ทำงาน วานผู้รู้ช่วยชี้แนะด้วยค่ะ
เริ่มหัวข้อโดย: isawa ที่ 16 มิถุนายน 2010, 13:38:04
อ้างถึง
<script type="text/javascript" language="javascript">
         function calculate()
         {
            var productPrice =  document.getElementById('productPrice').value;
            var shipPrice  = document.getElementById('shipPrice').value;
            var totalPrice = document.getElementById('totalPrice');
            var calculateToThai = document.getElementById('calculateToThai');
            totalPrice.value = parseInt(productPrice)   parseInt(shipPrice);
            calculateToThai.value = parseInt(totalPrice.value) * 36;
            var fee = document.getElementById('fee').value;
            calculateToCost.value = parseInt(totalPrice1.value) * 5;
            var fe1e = document.getElementById('fee1').value;
            calculateToCost.value = parseInt(totalPrice2.value) * 5;
            totalPrice2.value = parseInt(fee)   parseInt(fee1);   
         }
      </script>ค่าสินค้า
          <input type="text" id="productPrice"/>
  $<br/>
      ค่าขนส่งสินค้า 
       <input type="text" id="shipPrice"/>
      $<br/>
      คิดเป็นเงิน 
       <input type="text" id="totalPrice"/>
      $<br/>
      คิดเป็นเงินไทย
      <input type="text" id="calculateToThai"/>
      บาท
        <br/>
        บวกค่าธรรมเนียมธนาคารออนไลน์ 5%
        <br/>
        บวกค่าธรรมเนียมบัตรเครดิต 5%
 
<br/>
      ค่าใช้จ่ายทั้งสิ้นรวม <input type="text" id="toTalPrice2"/>
 
<br/>
      <input type="submit" value="Calculate" onClick="calculate()"/>

พยายามหันเขียนเองอยู่ แต่มันคำนวนแค่ช่วงแรก  :'( รบกวนด้วยนะคะ


ลองดูตรงโค๊ดที่ไฮไลสีแดงดูครับ


หัวข้อ: Re: สคริปไม่ทำงาน วานผู้รู้ช่วยชี้แนะด้วũ
เริ่มหัวข้อโดย: playinw ที่ 16 มิถุนายน 2010, 14:05:47
อันนี้ id ของ element ก็ผิด :(
ชื่อตัวแปรบางตัวไม่ได้ define แต่กลับเรียกใช้ :'(
Object บางอันไม่มีตัวตน  :-X
แถมอีกอย่างนะครับ ถึงคุณจะแก้ให้ใช้โค้ดนี้ได้ ก็ยังไม่ได้ตัวเลขที่ถูกต้องอยู่ดี

ให้ดูตรงค่าธรรมเนียม 5% คุณต้องเอาไปหารเอาจำนวนของเปอร์เซนมาบวก 5 แต่ในโค้ดคุณเอาไปคูณ 5 เฉยเลย
มันก็จะเท่ากับ ราคารวม คูณด้วยห้้า แล้วคูณด้วยห้า โอ้ว ค่าธรรมเนียมแพงกว่าสินค้าหลายเท่าตัวเลย T-T

ลองโค้ดที่ผมแก้ให้นี่ดูว่าคำนวนออกมาถูกไหม
http://demo.dig.in.th/cala.txt


หัวข้อ: Re: สคริปไม่ทำงาน วานผู้รู้ช่วยชี้แนะด้วยค่ะ
เริ่มหัวข้อโดย: mija ที่ 16 มิถุนายน 2010, 14:54:23
 :wanwan017: ขอบพระคุณมาก ๆ ค่ะ มือใหม่หัดเขียน อยากให้น้ำใจแต่ยังโพสไม่ถึง  :wanwan031: