Forum : document.write()
Brief description  about Online courses   join in Online courses
View Anonymous  Anonymouse 's Profile

document.write()

<html>
<head>
<script type="text/javascript">
function product(a,b)
{
return a*b;
}
</script>
</head>

<body>
<script type="text/javascript">
<input type="button" value="Click me" onclick=document.write(product(4,3))/>;
</script>

<p>The script in the body section calls a function with two parameters (4 and 3).</p>
<p>The function will return the product of these two parameters.</p>
</body>
</html>

document.write(product(4,3)) ...is not getting executed Y? What is the problem?
Asked by Anonymous Anonymouse | Aug 14, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Arun,

inside onclick event, call product function, eg. product(4,3)... if you want to return value, then return product(4,3);

onclick = "javascript: product(4,3);" OR
onclick = "javascript: return product(4,3);"

Regards,
Teacher
Aug 15, 2010