Results 1 to 3 of 3

Thread: I need to increase and decrease the quantity of values using images not buttons

  1. #1
    Join Date
    Jul 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I need to increase and decrease the quantity of values using images not buttons

    Hi Friends

    I am in trouble with some java script code.Plz help me.

    Query :

    I need to increase and decrease the quantity of values using images not buttons.(I have images "-" text box(value) and image "+" )

    If i click "-" image values should keep decreasing and if i click "+" image value should keep increasing .


    Regards
    Mahesh

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Hope this helps:
    HTML Code:
    <script type="text/javascript">
    var inp,def,rate;
    window.onload=function()
    {
    def=100; // Set the initial Value of input box
    rate=1; // Set the subtrahend / Add
    inp=document.getElementById('val');
    inp.value=def;
    document.getElementById('less').onclick=function()
    {inp.value=Number(document.getElementById('val').value)-rate;}
    document.getElementById('plus').onclick=function()
    {inp.value=Number(document.getElementById('val').value)+rate;}
    }
    </script>
    <img src="decrease.jpg" alt="lessen" id="less">
    <input type="text" readonly id="val">
    <img src="increase.jpg" alt="increase" id="plus">
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Check the following code

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
        <head>
            <title>Untitled Document</title>
            <style type="text/css">
                .add {
                    background-image: url(add.gif);
                    width: 14px;
                    height: 13px;                
    				position:absolute;
    				top:0;
    				left:0;				
                }
    			.inp{
    				position:absolute;
    				top:0;
    				left:16px;				
    			}
    			.minus{
    				background-image: url(minus.gif);
                    width: 14px;
                    height: 13px;                
    				position:absolute;
    				top:0;
    				left:165px;
    			}
    			
            </style>
            <script type="text/javascript">
    		function addMinus(op){
    			if(op === '+'){
    				document.forms['f1'].elements['value'].value = parseInt(document.forms['f1'].elements['value'].value) + 1;
    			}else{
    				document.forms['f1'].elements['value'].value = parseInt(document.forms['f1'].elements['value'].value) - 1;
    			}
    		}      
            </script>
        </head>
        <body>
            <div style="position: relative;top:0;left:0;">
                <form name="f1">
                    <div onclick="addMinus('+');return false;" class="add" ></div>
                    <input type="text" value="1000" name="value" class="inp" /><a href="#" onclick="addMinus('-');return false;" class="minus"></a>
                </form>
            </div>
        </body>
    </html>
    Find the attached + and - images. Unzip the images and store them with the web page that has the above code.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •