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,027

HOME > PHP > PHP Forum > ทำปุ่มเพิ่ม ลด ตัวเลขใน textbox แต่วา่ต้องการกำหนด ให้กดเพิ่มได้แค่ 5 และกดลบได้เเค่ 0 ห้ามให้ติดลบ



 

ทำปุ่มเพิ่ม ลด ตัวเลขใน textbox แต่วา่ต้องการกำหนด ให้กดเพิ่มได้แค่ 5 และกดลบได้เเค่ 0 ห้ามให้ติดลบ

 



Topic : 105211



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



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



11

ทำปุ่มเพิ่ม ลด ตัวเลขใน textbox
แต่วา่ต้องการกำหนด ให้กดเพิ่มได้แค่ 5
และกดลบได้เเค่ 0 ห้ามให้ติดลบ

เขียนไม่ถูกเลย



Tag : PHP, MySQL







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-01-29 16:03:36 By : PALM26 View : 8773 Reply : 3
 

 

No. 1



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

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

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

หลักการ
1. ค่าถึง 5 แล้วให้กดเพิ่มไม่ได้
2. ลดค่าถึง 0 แล้วให้กดลดไม่ได้


ลองไปทำดู






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-29 16:56:11 By : mangkunzo
 


 

No. 2



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



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

ตอนนี้ติดอยู่ที่ว่า หลังจากที่กดปุ่มเพิ่ม หรือ ลบ ค่ามันจะไปทั้งแถวค่ะ
Capture
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
    // This button will increment the value
    $('.qtyplus').click(function(e){
        // Stop acting like a button
        e.preventDefault();
        // Get the field name
        fieldName = $(this).attr('field');
        // Get its current value
        var currentVal = parseInt($('input[name='+fieldName+']').val());
        // If is not undefined
        if (!isNaN(currentVal )&& currentVal < 5) {
            // Increment
            $('input[name='+fieldName+']').val(currentVal + 1);
        } else {
            // Otherwise put a 0 there
            $('input[name='+fieldName+']').val(5);
        }
    });
    // This button will decrement the value till 0
    $(".qtyminus").click(function(e) {
        // Stop acting like a button
        e.preventDefault();
        // Get the field name
        fieldName = $(this).attr('field');
        // Get its current value
        var currentVal = parseInt($('input[name='+fieldName+']').val());
        // If it isn't undefined or its greater than 0
        if (!isNaN(currentVal) && currentVal > 0) {
            // Decrement one
            $('input[name='+fieldName+']').val(currentVal - 1);
        } else {
            // Otherwise put a 0 there
            $('input[name='+fieldName+']').val(0);
        }
    });
});

</script>

</head> 
<body>  
<form id='myform' action="save_estimate.php?sID=<?=$_GET["sID"];?>" method="post" name="form1" >
<table width="900" border="1" align="center" cellpadding="0" cellspacing="0">
        <tr align="center" id="three">    
           <td width="50" height="37"><b>#</b></td>
           <td width="120" align="center"><b>รหัสอะไหล่</b></td>
           <td width="241" align="center"><b>รายการอะไหล่</b></td>
           <td width="103" align="center"><b>เบิก/ทำสี</b></td>
           <td width="113" align="center"><b>สาเหตุที่เบิก</b></td>
           <td width="61" align="center"><b>ราคา</b></td>
           <td width="121" align="center"><b>จำนวน</b></td>
           <td width="73" align="center"><b>ราคารวม</b></td>
        </tr>
		<?
			$x=0;
            while($objResult = mysql_fetch_array($objQuery))
            {

		<tr bgcolor="<?=$bg;?>">        	
            <td height="39" align="center"><?=$x;?><input type="hidden" name="idno[<?=$x-1;?>]" id="idno[<?=$x-1;?>]" value="<?=$x;?>"></td>
            <td align="left"><?=$sp_code?></td>
            <td align="left"><?=$sp_name?></td>
              <input name="sp_name[<?=$x;?>]" type="hidden" value="<?=$sp_name;?>" />
              <input name="sp_code[<?=$x;?>]" type="hidden" value="<?=$sp_code;?>" />
              <input name="price[<?=$x;?>]"   type="hidden" value="<?=$price;?>" />
              <input name="group_no" type="hidden" value="<?=$group_no;?>" />
              <input name="brand"    type="hidden" value="<?=$brand;?>" />
              <input name="class"    type="hidden" value="<?=$class;?>" />
              <input name="type"     type="hidden" value="<?=$type;?>" />
              <input name="strno"    type="hidden" value="<?=$_GET["sID"];?>" />
            <td align="center">
            <div id="radio-demo">    
              <input type="checkbox"  name="chk_take[<?=$x;?>]" id="chk_take<?=$x;?>_1" value="1" 
              onClick="javaScript:if(this.checked)
              			{
                        document.form1.total<?=$x;?>.disabled=false;
                        document.form1.price<?=$x;?>.disabled=false;
                        document.form1.take<?=$x;?>.disabled=false;
                        }" >
              <label for="chk_take<?=$x;?>_1">เบิก</label>
              <input type="checkbox"  name="chk_take[<?=$x;?>]" id="chk_take<?=$x;?>_2" value="2" 
              onClick="javaScript:if(this.checked)
              			{ 
                        document.form1.total<?=$x;?>.disabled=true;
                        document.form1.price<?=$x;?>.disabled=true;
                        document.form1.take<?=$x;?>.disabled=true;
                        }">
              <label for="chk_take<?=$x;?>_2">ทำสี</label>
            </div>
           </td>
           <td align="center">
           <div id="radio-demo"> 
                <input type="radio"  name="cause_take[<?=$x;?>]" id="cause_take<?=$x;?>_1" value="1"/>
                <label for="cause_take<?=$x;?>_1">ชำรุด</label>
                <input type="radio"  name="cause_take[<?=$x;?>]" id="cause_take<?=$x;?>_2" value="2"/>
                <label for="cause_take<?=$x;?>_2">ไม่มี</label>
           </div>
           </td>
           <td align="center">
			   <?=number_format($price, 2, '.', ', ');?>
               <input type="hidden" name="price<?=$x;?>" value="<?=number_format($price, 2, '.', ', ');?>" size="8"  >
           </td>
           <td align="center">
               <input type='button' value='-' class='qtyminus' field='quantity' />
               <input type='text' name='quantity' value='0' class='qty' size="3" />
               <input type='button' value='+' class='qtyplus' field='quantity' />
           </td>
           <td align="center"><input type="text" name="total<?=$x;?>" id="total<?=$x;?>" value="0" readonly size="5"></td>
        </tr>
        <? } ?>
        <tr bgcolor="#f0e79b">
          <td height="33" colspan="6" align="center"><b>ราคารวม (บาท)</b></td>
          <td><input type="text" name="sum" id="sum" readonly size="8"> </td>
        </tr>
        <tr>
        	<td colspan="7">
            	<input type="hidden" name="hdnMaxLine" value="0">
                <input type="hidden" name="count" value="<?=$x;?>" />
            	<input type="submit" id="submit" value="บันทึกข้อมูล" style="width:75px; height:30px;"/>
            </td>
        </tr>
        </table>
</form>
</div>
</body>




ประวัติการแก้ไข
2014-01-30 15:36:10
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-30 15:35:23 By : PALM26
 

 

No. 3



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

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

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


ลองดูครับ http://jsfiddle.net/cvNTW/
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    // This button will increment the value
    $('.qtyplus').click(function(e){
        // Stop acting like a button
        e.preventDefault();
        // Get the field name
        var fieldName = $(this).prev();
        // Get its current value
        var currentVal = parseInt(fieldName.val());
        // If is not undefined
        if (!isNaN(currentVal )&& currentVal < 5) {
            // Increment
            fieldName.val(currentVal + 1);
        } else {
            // Otherwise put a 0 there
            fieldName.val(5);
        }
    });
    // This button will decrement the value till 0
    $(".qtyminus").click(function(e) {
        // Stop acting like a button
        e.preventDefault();
        // Get the field name
        var fieldName = $(this).next();
        // Get its current value
        var currentVal = parseInt(fieldName.val());
        // If it isn't undefined or its greater than 0
        if (!isNaN(currentVal) && currentVal > 0) {
            // Decrement one
            fieldName.val(currentVal - 1);
        } else {
            // Otherwise put a 0 there
            fieldName.val(0);
        }
    });
});
</script>

<form id='myform' method='POST' action='#'>
    <input type='button' value='-' class='qtyminus' field='quantity' />
    <input type='text' name='quantity' value='0' />
    <input type='button' value='+' class='qtyplus' field='quantity' /><br />
     <input type='button' value='-' class='qtyminus' field='quantity' />
    <input type='text' name='quantity' value='0' />
    <input type='button' value='+' class='qtyplus' field='quantity' /><br />
     <input type='button' value='-' class='qtyminus' field='quantity' />
    <input type='text' name='quantity' value='0' />
    <input type='button' value='+' class='qtyplus' field='quantity' />
</form>


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-30 15:52:53 By : sakuraei
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ทำปุ่มเพิ่ม ลด ตัวเลขใน textbox แต่วา่ต้องการกำหนด ให้กดเพิ่มได้แค่ 5 และกดลบได้เเค่ 0 ห้ามให้ติดลบ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 00
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 อัตราราคา คลิกที่นี่