Jquery using function to return a value
Created a JS function to add two numbers in index.js
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parstInt(number2);
var num3 = num1.num2;
return num3;Created a html page in Visual Studio
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<title></title>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.js">
</script>
<script src="index.js"> </script>
</head>
<body>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
<script type="text/javascript">
$('document').ready(function ()
$('#btnAdd').click(function ()
$('#total').val(add(num1, num2));
);
);
</script>
</body>
</html>
When we click on "Add" button, total should be displayed
But nothing happens with this code
javascript jquery html
add a comment |
Created a JS function to add two numbers in index.js
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parstInt(number2);
var num3 = num1.num2;
return num3;Created a html page in Visual Studio
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<title></title>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.js">
</script>
<script src="index.js"> </script>
</head>
<body>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
<script type="text/javascript">
$('document').ready(function ()
$('#btnAdd').click(function ()
$('#total').val(add(num1, num2));
);
);
</script>
</body>
</html>
When we click on "Add" button, total should be displayed
But nothing happens with this code
javascript jquery html
What do you hope to accomplish withnum1.num2
? How do you setnum1
andnum2
when callingadd(num1, num2)
inside the jQuery?
– vol7ron
Nov 14 '18 at 2:29
add a comment |
Created a JS function to add two numbers in index.js
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parstInt(number2);
var num3 = num1.num2;
return num3;Created a html page in Visual Studio
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<title></title>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.js">
</script>
<script src="index.js"> </script>
</head>
<body>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
<script type="text/javascript">
$('document').ready(function ()
$('#btnAdd').click(function ()
$('#total').val(add(num1, num2));
);
);
</script>
</body>
</html>
When we click on "Add" button, total should be displayed
But nothing happens with this code
javascript jquery html
Created a JS function to add two numbers in index.js
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parstInt(number2);
var num3 = num1.num2;
return num3;Created a html page in Visual Studio
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<title></title>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.js">
</script>
<script src="index.js"> </script>
</head>
<body>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
<script type="text/javascript">
$('document').ready(function ()
$('#btnAdd').click(function ()
$('#total').val(add(num1, num2));
);
);
</script>
</body>
</html>
When we click on "Add" button, total should be displayed
But nothing happens with this code
javascript jquery html
javascript jquery html
edited Nov 14 '18 at 2:24
Jack Bashford
7,46931338
7,46931338
asked Nov 14 '18 at 2:19
Sudhir JangamSudhir Jangam
163
163
What do you hope to accomplish withnum1.num2
? How do you setnum1
andnum2
when callingadd(num1, num2)
inside the jQuery?
– vol7ron
Nov 14 '18 at 2:29
add a comment |
What do you hope to accomplish withnum1.num2
? How do you setnum1
andnum2
when callingadd(num1, num2)
inside the jQuery?
– vol7ron
Nov 14 '18 at 2:29
What do you hope to accomplish with
num1.num2
? How do you set num1
and num2
when calling add(num1, num2)
inside the jQuery?– vol7ron
Nov 14 '18 at 2:29
What do you hope to accomplish with
num1.num2
? How do you set num1
and num2
when calling add(num1, num2)
inside the jQuery?– vol7ron
Nov 14 '18 at 2:29
add a comment |
3 Answers
3
active
oldest
votes
You have some errors on your code:
1) you have to get values from the inputs
elements.
2) You have a typo error on one of the parseInt()
methods.
3) To adds number you where using .
? Should no be the +
operator.
Check the next example with the fixes:
$('document').ready(function()
$('#btnAdd').click(function ()
var num1 = $("#num1").val();
var num2 = $("#num2").val();
$('#total').val(add(num1, num2));
);
);
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
Um, where are the typos in theparseInt()
methods in the OP's code? It looks fine to me.
– Jack Bashford
Nov 14 '18 at 2:30
1
this one:parstInt(number2);
– Shidersz
Nov 14 '18 at 2:31
Oh, right. I didn't see that.
– Jack Bashford
Nov 14 '18 at 2:36
I changed the code as below, still no change var num1 = $("#num1").val(); var num2 = $("#num2").val(); $('#total').val(add(num1, num2));
– Sudhir Jangam
Nov 14 '18 at 2:39
@JackBashford I also won't note it if wasn't for the help of the console debug from the snippet tool.
– Shidersz
Nov 14 '18 at 2:39
|
show 2 more comments
You haven't declared num1
and num2
when you're calling add
. Make your code this:
$('document').ready(function ()
$('#btnAdd').click(function ()
$('#total').val(add($("#num1").val(), $("#num2").val()));
);
);
And it should work.
EDIT: Change your add
function to this:
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
The .
operator doesn't add two numbers.
$('document').ready(function () $('#btnAdd').click(function () $('#total').val(add($("#num1").val(), $("#num2").val())); //$('#total').val(add(num1, num2)); ); );
– Sudhir Jangam
Nov 14 '18 at 2:28
still the same result
– Sudhir Jangam
Nov 14 '18 at 2:28
OK, I'll edit my post with what I believe to be the correct code.
– Jack Bashford
Nov 14 '18 at 2:28
$('document').ready(function () $('#btnAdd').click(function () $('#total').val(add($("#num1").val(), $("#num2").val())); //$('#total').val(add(num1, num2)); ); );
– Sudhir Jangam
Nov 14 '18 at 2:29
@SudhirJangam Fixed now, any better?
– Jack Bashford
Nov 14 '18 at 2:29
|
show 2 more comments
$('document').ready(function()
$('#btnAdd').click(function ()
var num1 = ( $("#num1").val()==""?0:$("#num1").val());
var num2 = ( $("#num2").val()==""?0:$("#num2").val());
$('#total').val(add(num1, num2));
);
);
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
Maybe an exception if the input is empty is necesary for your problem
( $("#num1").val()==""?0:$("#num1").val());
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292270%2fjquery-using-function-to-return-a-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have some errors on your code:
1) you have to get values from the inputs
elements.
2) You have a typo error on one of the parseInt()
methods.
3) To adds number you where using .
? Should no be the +
operator.
Check the next example with the fixes:
$('document').ready(function()
$('#btnAdd').click(function ()
var num1 = $("#num1").val();
var num2 = $("#num2").val();
$('#total').val(add(num1, num2));
);
);
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
Um, where are the typos in theparseInt()
methods in the OP's code? It looks fine to me.
– Jack Bashford
Nov 14 '18 at 2:30
1
this one:parstInt(number2);
– Shidersz
Nov 14 '18 at 2:31
Oh, right. I didn't see that.
– Jack Bashford
Nov 14 '18 at 2:36
I changed the code as below, still no change var num1 = $("#num1").val(); var num2 = $("#num2").val(); $('#total').val(add(num1, num2));
– Sudhir Jangam
Nov 14 '18 at 2:39
@JackBashford I also won't note it if wasn't for the help of the console debug from the snippet tool.
– Shidersz
Nov 14 '18 at 2:39
|
show 2 more comments
You have some errors on your code:
1) you have to get values from the inputs
elements.
2) You have a typo error on one of the parseInt()
methods.
3) To adds number you where using .
? Should no be the +
operator.
Check the next example with the fixes:
$('document').ready(function()
$('#btnAdd').click(function ()
var num1 = $("#num1").val();
var num2 = $("#num2").val();
$('#total').val(add(num1, num2));
);
);
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
Um, where are the typos in theparseInt()
methods in the OP's code? It looks fine to me.
– Jack Bashford
Nov 14 '18 at 2:30
1
this one:parstInt(number2);
– Shidersz
Nov 14 '18 at 2:31
Oh, right. I didn't see that.
– Jack Bashford
Nov 14 '18 at 2:36
I changed the code as below, still no change var num1 = $("#num1").val(); var num2 = $("#num2").val(); $('#total').val(add(num1, num2));
– Sudhir Jangam
Nov 14 '18 at 2:39
@JackBashford I also won't note it if wasn't for the help of the console debug from the snippet tool.
– Shidersz
Nov 14 '18 at 2:39
|
show 2 more comments
You have some errors on your code:
1) you have to get values from the inputs
elements.
2) You have a typo error on one of the parseInt()
methods.
3) To adds number you where using .
? Should no be the +
operator.
Check the next example with the fixes:
$('document').ready(function()
$('#btnAdd').click(function ()
var num1 = $("#num1").val();
var num2 = $("#num2").val();
$('#total').val(add(num1, num2));
);
);
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
You have some errors on your code:
1) you have to get values from the inputs
elements.
2) You have a typo error on one of the parseInt()
methods.
3) To adds number you where using .
? Should no be the +
operator.
Check the next example with the fixes:
$('document').ready(function()
$('#btnAdd').click(function ()
var num1 = $("#num1").val();
var num2 = $("#num2").val();
$('#total').val(add(num1, num2));
);
);
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
$('document').ready(function()
$('#btnAdd').click(function ()
var num1 = $("#num1").val();
var num2 = $("#num2").val();
$('#total').val(add(num1, num2));
);
);
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
$('document').ready(function()
$('#btnAdd').click(function ()
var num1 = $("#num1").val();
var num2 = $("#num2").val();
$('#total').val(add(num1, num2));
);
);
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
edited Nov 14 '18 at 2:32
answered Nov 14 '18 at 2:29
ShiderszShidersz
6,0692729
6,0692729
Um, where are the typos in theparseInt()
methods in the OP's code? It looks fine to me.
– Jack Bashford
Nov 14 '18 at 2:30
1
this one:parstInt(number2);
– Shidersz
Nov 14 '18 at 2:31
Oh, right. I didn't see that.
– Jack Bashford
Nov 14 '18 at 2:36
I changed the code as below, still no change var num1 = $("#num1").val(); var num2 = $("#num2").val(); $('#total').val(add(num1, num2));
– Sudhir Jangam
Nov 14 '18 at 2:39
@JackBashford I also won't note it if wasn't for the help of the console debug from the snippet tool.
– Shidersz
Nov 14 '18 at 2:39
|
show 2 more comments
Um, where are the typos in theparseInt()
methods in the OP's code? It looks fine to me.
– Jack Bashford
Nov 14 '18 at 2:30
1
this one:parstInt(number2);
– Shidersz
Nov 14 '18 at 2:31
Oh, right. I didn't see that.
– Jack Bashford
Nov 14 '18 at 2:36
I changed the code as below, still no change var num1 = $("#num1").val(); var num2 = $("#num2").val(); $('#total').val(add(num1, num2));
– Sudhir Jangam
Nov 14 '18 at 2:39
@JackBashford I also won't note it if wasn't for the help of the console debug from the snippet tool.
– Shidersz
Nov 14 '18 at 2:39
Um, where are the typos in the
parseInt()
methods in the OP's code? It looks fine to me.– Jack Bashford
Nov 14 '18 at 2:30
Um, where are the typos in the
parseInt()
methods in the OP's code? It looks fine to me.– Jack Bashford
Nov 14 '18 at 2:30
1
1
this one:
parstInt(number2);
– Shidersz
Nov 14 '18 at 2:31
this one:
parstInt(number2);
– Shidersz
Nov 14 '18 at 2:31
Oh, right. I didn't see that.
– Jack Bashford
Nov 14 '18 at 2:36
Oh, right. I didn't see that.
– Jack Bashford
Nov 14 '18 at 2:36
I changed the code as below, still no change var num1 = $("#num1").val(); var num2 = $("#num2").val(); $('#total').val(add(num1, num2));
– Sudhir Jangam
Nov 14 '18 at 2:39
I changed the code as below, still no change var num1 = $("#num1").val(); var num2 = $("#num2").val(); $('#total').val(add(num1, num2));
– Sudhir Jangam
Nov 14 '18 at 2:39
@JackBashford I also won't note it if wasn't for the help of the console debug from the snippet tool.
– Shidersz
Nov 14 '18 at 2:39
@JackBashford I also won't note it if wasn't for the help of the console debug from the snippet tool.
– Shidersz
Nov 14 '18 at 2:39
|
show 2 more comments
You haven't declared num1
and num2
when you're calling add
. Make your code this:
$('document').ready(function ()
$('#btnAdd').click(function ()
$('#total').val(add($("#num1").val(), $("#num2").val()));
);
);
And it should work.
EDIT: Change your add
function to this:
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
The .
operator doesn't add two numbers.
$('document').ready(function () $('#btnAdd').click(function () $('#total').val(add($("#num1").val(), $("#num2").val())); //$('#total').val(add(num1, num2)); ); );
– Sudhir Jangam
Nov 14 '18 at 2:28
still the same result
– Sudhir Jangam
Nov 14 '18 at 2:28
OK, I'll edit my post with what I believe to be the correct code.
– Jack Bashford
Nov 14 '18 at 2:28
$('document').ready(function () $('#btnAdd').click(function () $('#total').val(add($("#num1").val(), $("#num2").val())); //$('#total').val(add(num1, num2)); ); );
– Sudhir Jangam
Nov 14 '18 at 2:29
@SudhirJangam Fixed now, any better?
– Jack Bashford
Nov 14 '18 at 2:29
|
show 2 more comments
You haven't declared num1
and num2
when you're calling add
. Make your code this:
$('document').ready(function ()
$('#btnAdd').click(function ()
$('#total').val(add($("#num1").val(), $("#num2").val()));
);
);
And it should work.
EDIT: Change your add
function to this:
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
The .
operator doesn't add two numbers.
$('document').ready(function () $('#btnAdd').click(function () $('#total').val(add($("#num1").val(), $("#num2").val())); //$('#total').val(add(num1, num2)); ); );
– Sudhir Jangam
Nov 14 '18 at 2:28
still the same result
– Sudhir Jangam
Nov 14 '18 at 2:28
OK, I'll edit my post with what I believe to be the correct code.
– Jack Bashford
Nov 14 '18 at 2:28
$('document').ready(function () $('#btnAdd').click(function () $('#total').val(add($("#num1").val(), $("#num2").val())); //$('#total').val(add(num1, num2)); ); );
– Sudhir Jangam
Nov 14 '18 at 2:29
@SudhirJangam Fixed now, any better?
– Jack Bashford
Nov 14 '18 at 2:29
|
show 2 more comments
You haven't declared num1
and num2
when you're calling add
. Make your code this:
$('document').ready(function ()
$('#btnAdd').click(function ()
$('#total').val(add($("#num1").val(), $("#num2").val()));
);
);
And it should work.
EDIT: Change your add
function to this:
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
The .
operator doesn't add two numbers.
You haven't declared num1
and num2
when you're calling add
. Make your code this:
$('document').ready(function ()
$('#btnAdd').click(function ()
$('#total').val(add($("#num1").val(), $("#num2").val()));
);
);
And it should work.
EDIT: Change your add
function to this:
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
The .
operator doesn't add two numbers.
edited Nov 14 '18 at 2:42
Shidersz
6,0692729
6,0692729
answered Nov 14 '18 at 2:24
Jack BashfordJack Bashford
7,46931338
7,46931338
$('document').ready(function () $('#btnAdd').click(function () $('#total').val(add($("#num1").val(), $("#num2").val())); //$('#total').val(add(num1, num2)); ); );
– Sudhir Jangam
Nov 14 '18 at 2:28
still the same result
– Sudhir Jangam
Nov 14 '18 at 2:28
OK, I'll edit my post with what I believe to be the correct code.
– Jack Bashford
Nov 14 '18 at 2:28
$('document').ready(function () $('#btnAdd').click(function () $('#total').val(add($("#num1").val(), $("#num2").val())); //$('#total').val(add(num1, num2)); ); );
– Sudhir Jangam
Nov 14 '18 at 2:29
@SudhirJangam Fixed now, any better?
– Jack Bashford
Nov 14 '18 at 2:29
|
show 2 more comments
$('document').ready(function () $('#btnAdd').click(function () $('#total').val(add($("#num1").val(), $("#num2").val())); //$('#total').val(add(num1, num2)); ); );
– Sudhir Jangam
Nov 14 '18 at 2:28
still the same result
– Sudhir Jangam
Nov 14 '18 at 2:28
OK, I'll edit my post with what I believe to be the correct code.
– Jack Bashford
Nov 14 '18 at 2:28
$('document').ready(function () $('#btnAdd').click(function () $('#total').val(add($("#num1").val(), $("#num2").val())); //$('#total').val(add(num1, num2)); ); );
– Sudhir Jangam
Nov 14 '18 at 2:29
@SudhirJangam Fixed now, any better?
– Jack Bashford
Nov 14 '18 at 2:29
$('document').ready(function () $('#btnAdd').click(function () $('#total').val(add($("#num1").val(), $("#num2").val())); //$('#total').val(add(num1, num2)); ); );
– Sudhir Jangam
Nov 14 '18 at 2:28
$('document').ready(function () $('#btnAdd').click(function () $('#total').val(add($("#num1").val(), $("#num2").val())); //$('#total').val(add(num1, num2)); ); );
– Sudhir Jangam
Nov 14 '18 at 2:28
still the same result
– Sudhir Jangam
Nov 14 '18 at 2:28
still the same result
– Sudhir Jangam
Nov 14 '18 at 2:28
OK, I'll edit my post with what I believe to be the correct code.
– Jack Bashford
Nov 14 '18 at 2:28
OK, I'll edit my post with what I believe to be the correct code.
– Jack Bashford
Nov 14 '18 at 2:28
$('document').ready(function () $('#btnAdd').click(function () $('#total').val(add($("#num1").val(), $("#num2").val())); //$('#total').val(add(num1, num2)); ); );
– Sudhir Jangam
Nov 14 '18 at 2:29
$('document').ready(function () $('#btnAdd').click(function () $('#total').val(add($("#num1").val(), $("#num2").val())); //$('#total').val(add(num1, num2)); ); );
– Sudhir Jangam
Nov 14 '18 at 2:29
@SudhirJangam Fixed now, any better?
– Jack Bashford
Nov 14 '18 at 2:29
@SudhirJangam Fixed now, any better?
– Jack Bashford
Nov 14 '18 at 2:29
|
show 2 more comments
$('document').ready(function()
$('#btnAdd').click(function ()
var num1 = ( $("#num1").val()==""?0:$("#num1").val());
var num2 = ( $("#num2").val()==""?0:$("#num2").val());
$('#total').val(add(num1, num2));
);
);
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
Maybe an exception if the input is empty is necesary for your problem
( $("#num1").val()==""?0:$("#num1").val());
add a comment |
$('document').ready(function()
$('#btnAdd').click(function ()
var num1 = ( $("#num1").val()==""?0:$("#num1").val());
var num2 = ( $("#num2").val()==""?0:$("#num2").val());
$('#total').val(add(num1, num2));
);
);
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
Maybe an exception if the input is empty is necesary for your problem
( $("#num1").val()==""?0:$("#num1").val());
add a comment |
$('document').ready(function()
$('#btnAdd').click(function ()
var num1 = ( $("#num1").val()==""?0:$("#num1").val());
var num2 = ( $("#num2").val()==""?0:$("#num2").val());
$('#total').val(add(num1, num2));
);
);
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
Maybe an exception if the input is empty is necesary for your problem
( $("#num1").val()==""?0:$("#num1").val());
$('document').ready(function()
$('#btnAdd').click(function ()
var num1 = ( $("#num1").val()==""?0:$("#num1").val());
var num2 = ( $("#num2").val()==""?0:$("#num2").val());
$('#total').val(add(num1, num2));
);
);
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
Maybe an exception if the input is empty is necesary for your problem
( $("#num1").val()==""?0:$("#num1").val());
$('document').ready(function()
$('#btnAdd').click(function ()
var num1 = ( $("#num1").val()==""?0:$("#num1").val());
var num2 = ( $("#num2").val()==""?0:$("#num2").val());
$('#total').val(add(num1, num2));
);
);
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
$('document').ready(function()
$('#btnAdd').click(function ()
var num1 = ( $("#num1").val()==""?0:$("#num1").val());
var num2 = ( $("#num2").val()==""?0:$("#num2").val());
$('#total').val(add(num1, num2));
);
);
function add(number1, number2)
var num1 = parseInt(number1);
var num2 = parseInt(number2);
var num3 = num1 + num2;
return num3;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> Adding two numbers </h1>
<input id="num1" placeholder="0" />
<input id="num2" placeholder="0" />
<button id="btnAdd" type="button"> Add</button>
<input id="total" placeholder="0" readonly />
answered Nov 14 '18 at 3:22
YazsidYazsid
1555
1555
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292270%2fjquery-using-function-to-return-a-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What do you hope to accomplish with
num1.num2
? How do you setnum1
andnum2
when callingadd(num1, num2)
inside the jQuery?– vol7ron
Nov 14 '18 at 2:29