Forum : concatenate string with number and display result in alert box as well as web page
Brief description  about Online courses   join in Online courses
View Sri Bhargavi  Peesapati 's Profile

concatenate string with number and display result in alert box as well as web page

Hi, anywhere wrong in the below code? pls let me know.. Im getting output in alert box but not getting output on the webpage..

<html>
<head>
<title>assign-3(e)</title>
<SCRIPT language = JavaScript>

function add() {

var A = 'Hello World';
var B = 10;
C = (A B);
}

</SCRIPT>
</head>
<body>

<Input Type = Button NAME = b1 VALUE = "Add" onClick = "add(),alert(C),document.write(C)">

</body>
</html>
Asked by Sri Bhargavi Peesapati | Jul 10, 2010 |  Reply now
Replies (4)
View sri-bhargavi peesapati 's Profile
Thank U
Jul 14, 2010
View teacher siliconindia 's Profile
Hi Bharghavi,

Your code has some errors . I have given you the right code .

<html>
<head>
<title>assign-3(e)</title>
<SCRIPT language = JavaScript>

function add() {

var A = 'Hello World';
var B = 10;
C = (A+B);
alert(C);
document.write(C);
}

</SCRIPT>
</head>
<body>

<Input Type = Button NAME = b1 VALUE = "Add" onClick = "add()">


</body>
</html>
Jul 14, 2010
View ajaykanth h c 's Profile
Its better to do like this:


<html>
<head>
<title>assign-3(e)</title>
<SCRIPT language = JavaScript>

function add() {

var A = 'Hello World';
var B = 10;
C = (A+B);
alert(C);
document.write(C)
}

</SCRIPT>
</head>
<body>

<Input Type = Button NAME = b1 VALUE = "Add" onClick = "add();">

</body>
</html>
Jul 13, 2010
View sri-bhargavi peesapati 's Profile
pls assume 'plus' operator while adding the values...here its not displaying ..
Jul 10, 2010