Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HTML
<form name= "form1" onSonSumit="return">
    Enter your first number
    <input type ="text" name="nfirstEntry"><br>
    Enter your second Number
    <input type ="text" name="nSecondEntry"><br><br>
    Answer : 
    <input type="text" name="operation" value= "  "> <br>
    <input type=" button" name= "Add" value=" + " onClick="fncall()">
</form>
JavaScript
function fncall()
{
    var nResult;
    var nFirst, nSecond;
    nFirst= parseInt(form1.nFirstEntry.value);
    nSecond=parseInt(form1.nSecondEntry.value);
    nResult = fnAdd(nFirst,nSecond);
    form1.operation.value = nResult;
}

function fnAdd (nFirst,nSecond)
{
    return nFirst+nSecond;
}
https://codepen.io/Kizzyklicks/pen/powvVer[^]

What I have tried:

I have tried debugging it, but it seems not be working
Posted
Updated 25-Aug-21 6:41am
v2
Comments
raddevus 25-Aug-21 11:34am    
Add your html & code to something like codepen.io (click the Start Coding button on the left side & add your code). Save the code and link then let us know so we can see the entire code sample. Then we may be able to help you.
raddevus 25-Aug-21 11:40am    
Here's a very short snippet of code at codepen that uses some of your concepts:
https://codepen.io/raddevus/pen/KKqwRPa
Kizito A 25-Aug-21 11:59am    
Thanks a lot,
https://codepen.io/Kizzyklicks/pen/powvVer

1 solution

Quote:
HTML
<input type ="text" name="nfirstEntry">
JavaScript
nFirst= parseInt(form1.nFirstEntry.value);
Javascript is case-sensitive. nfirstEntry is not the same as nFirstEntry.

If you debug the code, or just look at the developer console when you click the button, you will see the error message:
form1.nFirstEntry is undefined

Either fix the <input>'s id to match the name used in your Javascript, or fix the name in your Javascript to match the id, and your code will start working.
 
Share this answer
 
Comments
Kizito A 25-Aug-21 16:10pm    
Thanks a lot, it worked just fine.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900