Multiple function in javascript
I want to use multiple functions in script.i without getting the computed value in the second textbox. I don't know what is wrong with my program. without returning a value.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
function fun1()
{
var z=5;
function fun3(x)
{
alert("i am fun3");
var y=x+z;
}
return y;
}
function fun2()
{
var a = document.getElementById("txt1").value;
var result = fun3(a);
document.getElementById("txt2").innerHTML=result;
}
</script>
</head>
<body>
Enter no: <input type="text" value="" id="txt1" onkeydown="fun2();">
Result: <input type="text" value="" id="txt2" />
</body>
</html>
+3
source to share
2 answers
Are you looking for something like this?
function fun1(a)
{
var z=5, y;
function fun3(x)
{
alert("i am fun3");
y=x+z;
}
fun3(a)
return y;
}
function fun2()
{
var a = document.getElementById("txt1").value;
var result = fun1(a);
document.getElementById("txt2").value=result;
}
EDIT:
I changed: document.getElementById("txt2").innerHtml=result;
from document.getElementById("txt2").value=result;
since txt2 is input
If not please clarify your question, I will edit it as soon as I have details.
EDIT 2
@Nitish finished on its own: jsfiddle.net/nitishkaushik/4sxb9d55/4
+2
source to share
this is what I want. and I got it. if anyone wants they can use :)
Enter: Result:
<script>
function fun1(a)
{
alert("Debugging 1st level="+a);
var z=5, y;
function fun3(x)
{
alert("Debugging 2nd level="+x);
y= (parseInt(x) + parseInt(z));
alert("Debugging 3rd level="+y);
}
fun3(a)
return y;
}
function fun2(val)
{ var result=0;
alert("value is"+val);
var result = fun1(val);
alert("Debugging 4th level="+result);
document.getElementById("txt2").value=result;
}
</script>
0
source to share