Take value from button and assign it to input

I want to make calculator. But I cant take and assign values.
Help plz

http://jsfiddle.net/Oleg_Ditkivskiy/2RPk9/1/

Comments

  • edited May 2013
    try this
    enyo.kind({
        name: "Calculator",
        components: [ 
            { name : "calculator", tag: "div", classes: "calculator", components:[ 
                { tag: "input", name: "input_clc", attributes: { readonly: 'readonly',value:''}},
            	{ kind: "Button", name: "button1" , attributes: {value : 1 }, content: "1", ontap: "addContents" },
            	{ kind: "Button", name: "button2" ,content: "2" , ontap: "addContents"},
            	{ kind: "Button", content: "3" , ontap: "addContents"},
            	{ kind: "Button", content: "C" , ontap: "addContents"},
            	{ kind: "Button", content: "4" , ontap: "addContents"},
            	{ kind: "Button", content: "5" , ontap: "addContents"},
            	{ kind: "Button", content: "6" , ontap: "addContents"},
            	{ kind: "Button", content: "+" , ontap: "addContents"},
            	{ kind: "Button", content: "7" , ontap: "addContents"},
            	{ kind: "Button", content: "8" , ontap: "addContents"},
            	{ kind: "Button", content: "9" , ontap: "addContents"},
            	{ kind: "Button", content: "-" , ontap: "addContents"},
            	{ kind: "Button", content: "0" , ontap: "addContents"},
            	{ kind: "Button", content: "," , ontap: "addContents"},
            	{ kind: "Button", content: "x" , ontap: "addContents"},
            	{ kind: "Button", content: "/" , ontap: "addContents"},
            	{ kind: "Button", classes: "equally", content: "=" , ontap: "addContents"},
            	
             	   ]
             	
            }
        ],
    
        addContents : function(inSender, inEvent){
      	var one = inSender.getContent();
            console.log(this.$.calculator.components[0]);
      	    this.$.calculator.children[0].value=(one);
            this.$.calculator.children[0].setAttribute("value",(one));
        }
    
        
            
    });
    it needs some updating though, but you get the idea
  • This should be of assistance: http://jsfiddle.net/arthurthornton/XrL8k/

    In my fiddle, I added a handlers block so that any ontap event will be caught by your calculator kind. In there, it is able to determine if it was a Button that was tapped and, if so, it can extract the numerical value (0-9) or the control key (such as +, -, or =) and you can act appropriately based on the tapped button.
Sign In or Register to comment.