Skip to Content
author's profile photo Former Member
Former Member

Hi i am able to run the SAP UI5 arithematic operation in eclipse but the same code doesn't give any output in sap web ide.

<script type="text/javascript">

var oLabel1 = new sap.ui.commons.Label("l1");

oLabel1.setText("Number1");

oLabel1.placeAt("content");

var oInput1 = new sap.ui.commons.TextField('input1');

//oInput1.setValue("Some Text");

oInput1.setTooltip("Input Positive number1");

//oInput1.attachChange(function(){alert('Text changed to :'+ oInput1.getValue());})

oInput1.placeAt("content");

var oLabel2 = new sap.ui.commons.Label("l2");

oLabel2.setText("Number2");

oLabel2.placeAt("content1");

var oInput2 = new sap.ui.commons.TextField('input2');

//oInput1.setValue("Some Text");

oInput2.setTooltip("Input Positive Number2");

//oInput1.attachChange(function(){alert('Text changed to :'+ oInput1.getValue());})

oInput2.placeAt("content1");

var oLabel3 = new sap.ui.commons.Label("l3");

oLabel3.setText("Result");

oLabel3.placeAt("content2");

var oInput3 = new sap.ui.commons.TextField('Result');

//oInput1.setValue("Some Text");

oInput3.setTooltip("Result");

//oInput1.attachChange(function(){alert('Text changed to :'+ oInput1.getValue());})

oInput3.placeAt("content2");

var myButton1=new sap.ui.commons.Button({

text:"Add",

style:sap.ui.commons.ButtonStyle.Emph,

//icon : "C:/Users/MM0387/Pictures/venu.png",

//"Alert from SAP UI5 First Program " +myButton.getText());

press:function()

{

var oTF1 = sap.ui.getCore().getElementById("input1").getValue();

var oTF2 = sap.ui.getCore().getElementById("input2").getValue();

if(oTF1<0 || oTF2<0)

alert("Enter only Positive Numbers");

else

var oTF3 = sap.ui.getCore().getElementById("Result");

oTF3.setValue(+oTF1 + +oTF2);

}

}).placeAt("content3");

// myButton.attachPress(oController.handleButtonClicked);

var myButton2=new sap.ui.commons.Button({

text:"Subtract",

style:sap.ui.commons.ButtonStyle.Emph,

//icon : "C:/Users/MM0387/Pictures/venu.png",

//"Alert from SAP UI5 First Program " +myButton.getText());

press:function()

{

var oTF1 = sap.ui.getCore().getElementById("input1").getValue();

var oTF2 = sap.ui.getCore().getElementById("input2").getValue();

if(oTF1<0 || oTF2<0)

alert("Enter only Positive Numbers");

else

var oTF3 = sap.ui.getCore().getElementById("Result");

oTF3.setValue(+oTF1 - +oTF2);

}

}).placeAt("content3");

var myButton3=new sap.ui.commons.Button({

text:"Divide",

style:sap.ui.commons.ButtonStyle.Emph,

//icon : "C:/Users/MM0387/Pictures/venu.png",

//"Alert from SAP UI5 First Program " +myButton.getText());

press:function()

{

var oTF1 = sap.ui.getCore().getElementById("input1").getValue();

var oTF2 = sap.ui.getCore().getElementById("input2").getValue();

if(oTF1<0 || oTF2<0)

alert("Enter only Positive Numbers");

else

var oTF3 = sap.ui.getCore().getElementById("Result");

oTF3.setValue(+oTF1 / +oTF2);

}

}).placeAt("content3");

var myButton4=new sap.ui.commons.Button({

text:"Multiply",

style:sap.ui.commons.ButtonStyle.Emph,

//icon : "C:/Users/MM0387/Pictures/venu.png",

//"Alert from SAP UI5 First Program " +myButton.getText());

press:function()

{

var oTF1 = sap.ui.getCore().getElementById("input1").getValue();

var oTF2 = sap.ui.getCore().getElementById("input2").getValue();

if(oTF1<0 || oTF2<0)

alert("Enter only Positive Numbers");

else

var oTF3 = sap.ui.getCore().getElementById("Result");

oTF3.setValue(+oTF1 * +oTF2);

}

}).placeAt("content3");

myButton1.setTooltip("Adds the values of Number1 & Number2");

myButton2.setTooltip("Subtracts the value from Number1 & Number2");

myButton3.setTooltip("Divides the value from Number1 & Number2");

myButton4.setTooltip("Provides the Product value of Number1 & Number2");

</script>

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Jan 18, 2016 at 06:59 AM

    Hi,

    It´s most probably because the corresponding SAP UI5 libraries are not loaded. I tried your coding in WebIDE and added

    sap.ui.require(["sap/ui/commons/Label", "sap/ui/commons/TextField", "sap/ui/commons/Button"], function(Label, TextField, Button){
    var oLabel1 = new sap.ui.commons.Label("l1");
    ...
    myButton4.setTooltip("Provides the Product value of Number1 & Number2");
    });
    

    as surrounding block and it worked. However, I think that´s all in all not a good coding style (if this should be the coding for a productive app; for just testing it´s ok).

    Best regards,

    Sebastian

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 18, 2016 at 07:06 AM

    Thank you very much & this was just my first try as a test in sap web ide,

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.