Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > PHP > PHP Forum > ช่วยดูให้หน่อยค่ะรวมตัวเลขและแก้ไขไม่ได้ค่ะ function toTaal()



 

ช่วยดูให้หน่อยค่ะรวมตัวเลขและแก้ไขไม่ได้ค่ะ function toTaal()

 



Topic : 024853



โพสกระทู้ ( 54 )
บทความ ( 0 )



สถานะออฟไลน์




<html>
<head>
<script>
function toTaal()
{

A1=document.form1.A1.value;
A2=document.form1.B1.value;
A3=document.form1.C1.value;


var sumval = A1+A2+A3;

document.form1.total.value=parseInt(A1+A2+A3);
//document.form1.total.value = sumval;


}
</script>
<script language="JavaScript">
function subFormA()
{
var j = 0;
var radio_buttons = new Array();
var the_form = window.document.forms[0];
for(var i=5; i<the_form.length; i++)
{
var temp = the_form.elements[i].type;
if((temp == "radio") && (the_form.elements[i].checked)) { radio_buttons[j] = the_form.elements[i].value; j++; }
}
for(var k=0; k<radio_buttons.length; k++)
{
document.form1.A1.value=(radio_buttons[k]*10);
}
}

function subFormB()
{
var j = 0;
var radio_buttons = new Array();
var the_form = window.document.forms[0];
for(var i=5; i<the_form.length; i++)
{
var temp = the_form.elements[i].type;
if((temp == "radio") && (the_form.elements[i].checked)) { radio_buttons[j] = the_form.elements[i].value; j++; }
}
for(var k=0; k<radio_buttons.length; k++)
{
document.form1.B1.value=(radio_buttons[k]*5);
}
}


function subFormC()
{
var j = 0;
var radio_buttons = new Array();
var the_form = window.document.forms[0];
for(var i=5; i<the_form.length; i++)
{
var temp = the_form.elements[i].type;
if((temp == "radio") && (the_form.elements[i].checked)) { radio_buttons[j] = the_form.elements[i].value; j++; }
}
for(var k=0; k<radio_buttons.length; k++)
{
document.form1.C1.value=(radio_buttons[k]);
}
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874"></head>

<body><form id="form1" name="form1" method="post">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input name="A" type="radio" value="0" onClick="subFormA()"/>
test0 </td>
</tr>
<tr>
<td><input name="A" type="radio" value="1" onClick="subFormA()"/>
test1</td>
</tr>
<tr>
<td><input name="A" type="radio" value="2" onClick="subFormA()"/>
test2</td>
</tr>
<tr>
<td><input name="A" type="radio" value="3" onClick="subFormA()"/>
test3</td>
</tr>
<tr>
<td><input name="A" type="radio" value="4" onClick="subFormA()"/>
test4*10</td>
</tr>
<tr>
<td>totaal
<input name="A1" type="text" id="A1"/></td>
</tr>
</table>
<br />
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input name="B" type="radio" value="0" onClick="subFormB()"/>
test0 </td>
</tr>
<tr>
<td><input name="B" type="radio" value="1" onClick="subFormB()"/>
test1</td>
</tr>
<tr>
<td><input name="B" type="radio" value="2" onClick="subFormB()"/>
test2</td>
</tr>
<tr>
<td><input name="B" type="radio" value="3" onClick="subFormB()"/>
test3</td>
</tr>
<tr>
<td><input name="B" type="radio" value="4" onClick="subFormB()"/>
test4</td>
</tr>
<tr>
<td>5</td>
</tr>
<tr>
<td>totaal
<input name="B1" type="text" id="B1"/></td>
</tr>
</table>
<br>
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input name="C" type="radio" value="0" onClick="subFormC()"/>
test0 </td>
</tr>
<tr>
<td><input name="C" type="radio" value="1" onClick="subFormC()"/>
test1</td>
</tr>
<tr>
<td><input name="C" type="radio" value="2" onClick="subFormC()"/>
test2</td>
</tr>
<tr>
<td><input name="C" type="radio" value="3" onClick="subFormC()"/>
test3</td>
</tr>
<tr>
<td><input name="C" type="radio" value="4" onClick="subFormC()"/>
test4</td>
</tr>
<tr>
<td>totaal
<input name="C1" type="text" id="C1" value=""/></td>
</tr>
</table>
<br>
<p>
<input name="totaal" type="button" id="totaal" value="Totaal" onClick="toTaal()"/>
</p>
<p>totaal
<input name="total" type="text" id="total"/>
</p>
</form>
</body>
</html>



จากโค้ดนี้ ไม่สามารถรวมผลรวมที่ช่องรวมได้ค่ะ และเมื่อกลับไปแก้ไขตัวที่เลือกก็ไม่สามารถแก้ไขได้ ผู้รู้ช่วยชี้แนะด้วยค่ะ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-02-19 16:11:14 By : kenji View : 766 Reply : 2
 

 

No. 1



โพสกระทู้ ( 95 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ที่ทำมาก็มาถูกทางแล้วครับ แต่ว่า การวนหาค่าของ Radio ทำให้ดูทำงานได้ยากไปหน่อย
ผมลองแก้ไขให้ โดยการทำการส่งค่ามาจาก Radio โดยตรงเลย เพื่อลดขั้นตอนลง

ส่วนการรวมค่า parseInt ต้องแยกใช้ครับ เอาค่ามา + กันก่อน แล้วค่อย parseInt จึงทำให้ไม่ได้เป็นค่าตัวเลข

<html>
<head>
<script>
function toTaal() {
A1=document.form1.A1.value;
A2=document.form1.B1.value;
A3=document.form1.C1.value;

var sumval = 0;
if(A1!="") sumval += parseInt(A1);
if(A2!="") sumval += parseInt(A2);
if(A3!="") sumval += parseInt(A3);
document.form1.total.value = sumval;
}

function subFormA(value) {
document.form1.A1.value=value*10;
}

function subFormB(value)
{
document.form1.B1.value=value*5;
}


function subFormC(value) {
document.form1.C1.value=value*10;
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874"></head>
<body>
<form id="form1" name="form1" method="post">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr><td><input name="A" type="radio" value="0" onClick="subFormA(this.value)"/> test0 </td></tr>
<tr><td><input name="A" type="radio" value="1" onClick="subFormA(this.value)"/> test1</td></tr>
<tr><td><input name="A" type="radio" value="2" onClick="subFormA(this.value)"/> test2</td></tr>
<tr><td><input name="A" type="radio" value="3" onClick="subFormA(this.value)"/> test3</td></tr>
<tr><td><input name="A" type="radio" value="4" onClick="subFormA(this.value)"/> test4</td></tr>
<tr><td>totaal <input name="A1" type="text" id="A1"/></td></tr>
</table>
<br />
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr><td><input name="B" type="radio" value="0" onClick="subFormB(this.value)"/> test0 </td></tr>
<tr><td><input name="B" type="radio" value="1" onClick="subFormB(this.value)"/> test1</td></tr>
<tr><td><input name="B" type="radio" value="2" onClick="subFormB(this.value)"/> test2</td></tr>
<tr><td><input name="B" type="radio" value="3" onClick="subFormB(this.value)"/> test3</td></tr>
<tr><td><input name="B" type="radio" value="4" onClick="subFormB(this.value)"/> test4</td></tr>
<tr><td>totaal <input name="B1" type="text" id="B1"/></td></tr>
</table>
<br>
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr><td><input name="C" type="radio" value="0" onClick="subFormC(this.value)"/> test0 </td></tr>
<tr><td><input name="C" type="radio" value="1" onClick="subFormC(this.value)"/> test1</td></tr>
<tr><td><input name="C" type="radio" value="2" onClick="subFormC(this.value)"/> test2</td></tr>
<tr><td><input name="C" type="radio" value="3" onClick="subFormC(this.value)"/> test3</td></tr>
<tr><td><input name="C" type="radio" value="4" onClick="subFormC(this.value)"/> test4</td></tr>
<tr><td>totaal <input name="C1" type="text" id="C1" value=""/></td></tr>
</table>
<br>
<p><input name="totaal" type="button" id="totaal" value="Totaal" onClick="toTaal()"/></p>
<p>totaal <input name="total" type="text" id="total"/></p>
</form>
</body>
</html>







Date : 2009-02-19 18:13:22 By : p_latplee
 


 

No. 2



โพสกระทู้ ( 54 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณ คุณ -=[ANT]=- มาก ๆ เลยค่ะ ที่ช่วยดูให้
Date : 2009-02-20 11:46:34 By : kenji
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยดูให้หน่อยค่ะรวมตัวเลขและแก้ไขไม่ได้ค่ะ function toTaal()
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่