Cannot get the number of var using javascriptWhat is innerHTML on input elements?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?var functionName = function() vs function functionName() Which equals operator (== vs ===) should be used in JavaScript comparisons?What's the difference between using “let” and “var”?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?
Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?
"listening to me about as much as you're listening to this pole here"
I see my dog run
Calculate Levenshtein distance between two strings in Python
How to make payment on the internet without leaving a money trail?
Ideas for colorfully and clearly highlighting graph edges according to weights
What do the Banks children have against barley water?
OA final episode explanation
Does it makes sense to buy a new cycle to learn riding?
Could Giant Ground Sloths have been a Good Pack Animal for the Ancient Mayans
Are cabin dividers used to "hide" the flex of the airplane?
Denied boarding due to overcrowding, Sparpreis ticket. What are my rights?
What is the offset in a seaplane's hull?
Does the average primeness of natural numbers tend to zero?
How to move the player while also allowing forces to affect it
Check if two datetimes are between two others
"My colleague's body is amazing"
Why is making salt water prohibited on Shabbat?
How to deal with fear of taking dependencies
Landlord wants to switch my lease to a "Land contract" to "get back at the city"
Re-submission of rejected manuscript without informing co-authors
Can a planet have a different gravitational pull depending on its location in orbit around its sun?
If a centaur druid Wild Shapes into a Giant Elk, do their Charge features stack?
What are the advantages and disadvantages of running one shots compared to campaigns?
Cannot get the number of var using javascript
What is innerHTML on input elements?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?var functionName = function() vs function functionName() Which equals operator (== vs ===) should be used in JavaScript comparisons?What's the difference between using “let” and “var”?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have this certain problem where I cannot get the number value of 'currentStock' var data inside an HTML file using JavaScript. I have this on my HTML file in script tag:
By the way, due to the HTML being too large, and also it was not originally my script, but from a friend who was asking for some help on adding some features in it, I can't upload the whole script as it will be going to be too long. The whole HTML script has 14076 characters with 289 lines.
I have only studied java and not javascript with HTML, so I need help with this one.
<script>
window.onload = function()
var goDown = document.getElementById('uniqueNav');
var goRight = document.querySelector('.clothesNav');
var goUp = document.querySelector('.shrink');
goDown.style.marginTop = "0px";
goRight.style.marginLeft = "5px";
goUp.style.height = "0px";
$('document').ready(function()
var name = "Ombre Printed Shirt";
var price = "P499.00";
var initialStock = 0;
var currentStock = initialStock;
document.querySelector('#clothTitle').innerHTML = "" +name;
document.querySelector('#clothPrice').innerHTML = "Price: " +price;
document.querySelector('#PITitle').innerHTML = "" +name;
document.querySelector('#PIPrice').innerHTML = "Price: " +price;
document.querySelector('#currentStock').innerHTML = "CurrentStocks: " +currentStock;
); //------------------------Change This Every Document ----------------------------//
</script>
then this in my JavaScript File:
var cStocks = document.getElementById('currentStock').data;
alert(typeof cStocks);
alert("Data in cStocks = " + cStocks);
if (!cStocks) cStocks = 0; alert("cStocks, not a valid number");
if ((cStocks <= 0) == true)
document.querySelector('.clothButton').style.display='none';
document.querySelector('.clothButtonDisabled').style.display='flex';
else
document.querySelector('.clothButton').style.display='flex';
document.querySelector('.clothButtonDisabled').style.display='none';
upon loading the page, the alert says thaat the data type is undefined. I don't know what's happening with my code. did I miss something?
By the way, I have JQuery on my HTML page. it says JQuery v3.3.1 as a version
javascript jquery html
|
show 2 more comments
I have this certain problem where I cannot get the number value of 'currentStock' var data inside an HTML file using JavaScript. I have this on my HTML file in script tag:
By the way, due to the HTML being too large, and also it was not originally my script, but from a friend who was asking for some help on adding some features in it, I can't upload the whole script as it will be going to be too long. The whole HTML script has 14076 characters with 289 lines.
I have only studied java and not javascript with HTML, so I need help with this one.
<script>
window.onload = function()
var goDown = document.getElementById('uniqueNav');
var goRight = document.querySelector('.clothesNav');
var goUp = document.querySelector('.shrink');
goDown.style.marginTop = "0px";
goRight.style.marginLeft = "5px";
goUp.style.height = "0px";
$('document').ready(function()
var name = "Ombre Printed Shirt";
var price = "P499.00";
var initialStock = 0;
var currentStock = initialStock;
document.querySelector('#clothTitle').innerHTML = "" +name;
document.querySelector('#clothPrice').innerHTML = "Price: " +price;
document.querySelector('#PITitle').innerHTML = "" +name;
document.querySelector('#PIPrice').innerHTML = "Price: " +price;
document.querySelector('#currentStock').innerHTML = "CurrentStocks: " +currentStock;
); //------------------------Change This Every Document ----------------------------//
</script>
then this in my JavaScript File:
var cStocks = document.getElementById('currentStock').data;
alert(typeof cStocks);
alert("Data in cStocks = " + cStocks);
if (!cStocks) cStocks = 0; alert("cStocks, not a valid number");
if ((cStocks <= 0) == true)
document.querySelector('.clothButton').style.display='none';
document.querySelector('.clothButtonDisabled').style.display='flex';
else
document.querySelector('.clothButton').style.display='flex';
document.querySelector('.clothButtonDisabled').style.display='none';
upon loading the page, the alert says thaat the data type is undefined. I don't know what's happening with my code. did I miss something?
By the way, I have JQuery on my HTML page. it says JQuery v3.3.1 as a version
javascript jquery html
1
Please add your entire HTML file.
– Jack Bashford
Mar 22 at 1:42
1
"cannot get the number of var" makes very little sense
– Pointy
Mar 22 at 1:44
1
Assuming it's the variablecStocksthat comes back as undefined, why would a DOM element have adataproperty? Are you sure you didn't mean to use either jQuery'sdata()orelement.dataset.dataetc?
– adeneo
Mar 22 at 1:46
I mean Number Data set in a var container @Pointy
– SolarPH
Mar 22 at 1:48
By the way, forgot to change it back to .value, but same thing happens @adeneo
– SolarPH
Mar 22 at 1:49
|
show 2 more comments
I have this certain problem where I cannot get the number value of 'currentStock' var data inside an HTML file using JavaScript. I have this on my HTML file in script tag:
By the way, due to the HTML being too large, and also it was not originally my script, but from a friend who was asking for some help on adding some features in it, I can't upload the whole script as it will be going to be too long. The whole HTML script has 14076 characters with 289 lines.
I have only studied java and not javascript with HTML, so I need help with this one.
<script>
window.onload = function()
var goDown = document.getElementById('uniqueNav');
var goRight = document.querySelector('.clothesNav');
var goUp = document.querySelector('.shrink');
goDown.style.marginTop = "0px";
goRight.style.marginLeft = "5px";
goUp.style.height = "0px";
$('document').ready(function()
var name = "Ombre Printed Shirt";
var price = "P499.00";
var initialStock = 0;
var currentStock = initialStock;
document.querySelector('#clothTitle').innerHTML = "" +name;
document.querySelector('#clothPrice').innerHTML = "Price: " +price;
document.querySelector('#PITitle').innerHTML = "" +name;
document.querySelector('#PIPrice').innerHTML = "Price: " +price;
document.querySelector('#currentStock').innerHTML = "CurrentStocks: " +currentStock;
); //------------------------Change This Every Document ----------------------------//
</script>
then this in my JavaScript File:
var cStocks = document.getElementById('currentStock').data;
alert(typeof cStocks);
alert("Data in cStocks = " + cStocks);
if (!cStocks) cStocks = 0; alert("cStocks, not a valid number");
if ((cStocks <= 0) == true)
document.querySelector('.clothButton').style.display='none';
document.querySelector('.clothButtonDisabled').style.display='flex';
else
document.querySelector('.clothButton').style.display='flex';
document.querySelector('.clothButtonDisabled').style.display='none';
upon loading the page, the alert says thaat the data type is undefined. I don't know what's happening with my code. did I miss something?
By the way, I have JQuery on my HTML page. it says JQuery v3.3.1 as a version
javascript jquery html
I have this certain problem where I cannot get the number value of 'currentStock' var data inside an HTML file using JavaScript. I have this on my HTML file in script tag:
By the way, due to the HTML being too large, and also it was not originally my script, but from a friend who was asking for some help on adding some features in it, I can't upload the whole script as it will be going to be too long. The whole HTML script has 14076 characters with 289 lines.
I have only studied java and not javascript with HTML, so I need help with this one.
<script>
window.onload = function()
var goDown = document.getElementById('uniqueNav');
var goRight = document.querySelector('.clothesNav');
var goUp = document.querySelector('.shrink');
goDown.style.marginTop = "0px";
goRight.style.marginLeft = "5px";
goUp.style.height = "0px";
$('document').ready(function()
var name = "Ombre Printed Shirt";
var price = "P499.00";
var initialStock = 0;
var currentStock = initialStock;
document.querySelector('#clothTitle').innerHTML = "" +name;
document.querySelector('#clothPrice').innerHTML = "Price: " +price;
document.querySelector('#PITitle').innerHTML = "" +name;
document.querySelector('#PIPrice').innerHTML = "Price: " +price;
document.querySelector('#currentStock').innerHTML = "CurrentStocks: " +currentStock;
); //------------------------Change This Every Document ----------------------------//
</script>
then this in my JavaScript File:
var cStocks = document.getElementById('currentStock').data;
alert(typeof cStocks);
alert("Data in cStocks = " + cStocks);
if (!cStocks) cStocks = 0; alert("cStocks, not a valid number");
if ((cStocks <= 0) == true)
document.querySelector('.clothButton').style.display='none';
document.querySelector('.clothButtonDisabled').style.display='flex';
else
document.querySelector('.clothButton').style.display='flex';
document.querySelector('.clothButtonDisabled').style.display='none';
upon loading the page, the alert says thaat the data type is undefined. I don't know what's happening with my code. did I miss something?
By the way, I have JQuery on my HTML page. it says JQuery v3.3.1 as a version
javascript jquery html
javascript jquery html
edited Mar 22 at 5:56
N8888
349211
349211
asked Mar 22 at 1:41
SolarPHSolarPH
41
41
1
Please add your entire HTML file.
– Jack Bashford
Mar 22 at 1:42
1
"cannot get the number of var" makes very little sense
– Pointy
Mar 22 at 1:44
1
Assuming it's the variablecStocksthat comes back as undefined, why would a DOM element have adataproperty? Are you sure you didn't mean to use either jQuery'sdata()orelement.dataset.dataetc?
– adeneo
Mar 22 at 1:46
I mean Number Data set in a var container @Pointy
– SolarPH
Mar 22 at 1:48
By the way, forgot to change it back to .value, but same thing happens @adeneo
– SolarPH
Mar 22 at 1:49
|
show 2 more comments
1
Please add your entire HTML file.
– Jack Bashford
Mar 22 at 1:42
1
"cannot get the number of var" makes very little sense
– Pointy
Mar 22 at 1:44
1
Assuming it's the variablecStocksthat comes back as undefined, why would a DOM element have adataproperty? Are you sure you didn't mean to use either jQuery'sdata()orelement.dataset.dataetc?
– adeneo
Mar 22 at 1:46
I mean Number Data set in a var container @Pointy
– SolarPH
Mar 22 at 1:48
By the way, forgot to change it back to .value, but same thing happens @adeneo
– SolarPH
Mar 22 at 1:49
1
1
Please add your entire HTML file.
– Jack Bashford
Mar 22 at 1:42
Please add your entire HTML file.
– Jack Bashford
Mar 22 at 1:42
1
1
"cannot get the number of var" makes very little sense
– Pointy
Mar 22 at 1:44
"cannot get the number of var" makes very little sense
– Pointy
Mar 22 at 1:44
1
1
Assuming it's the variable
cStocks that comes back as undefined, why would a DOM element have a data property? Are you sure you didn't mean to use either jQuery's data() or element.dataset.data etc?– adeneo
Mar 22 at 1:46
Assuming it's the variable
cStocks that comes back as undefined, why would a DOM element have a data property? Are you sure you didn't mean to use either jQuery's data() or element.dataset.data etc?– adeneo
Mar 22 at 1:46
I mean Number Data set in a var container @Pointy
– SolarPH
Mar 22 at 1:48
I mean Number Data set in a var container @Pointy
– SolarPH
Mar 22 at 1:48
By the way, forgot to change it back to .value, but same thing happens @adeneo
– SolarPH
Mar 22 at 1:49
By the way, forgot to change it back to .value, but same thing happens @adeneo
– SolarPH
Mar 22 at 1:49
|
show 2 more comments
1 Answer
1
active
oldest
votes
It doesn't look to me like #currentStock will have a data attribute, or value attribute (which is for inputs), so of course the js returns undefined. Right now it looks like #currentStock is having the innerHTML set on the document.ready to Current Stocks: 0
You do have an accessible variable, currentStock, which is defined during document.ready. Why aren't you accessing it directly? It will have the numeric value in it already. All you can get from #currentStock is the html you generated on document.ready, and you'd have to parse the number out of it, when it's available in raw form in the js variable currentStock.
I also tried to put it inside a separate script tag, but it behaves the same. I don't know if I made the variable data accessible by the javascript file.
– SolarPH
Mar 22 at 2:25
What I'm saying is that cStocks would be expected to contain undefined, because it's getting assigned the value of document.getElementById('currentStock').data, and there's no such thing unless #currentStock explicitly has a data attribute. Does it? And if so, where is it getting set? There's also no such thing as document.getElementById('currentStock').value unless #currentStock is an input element. Is it? If it is, where is the value getting set, and what is it getting set to? Let me put together a fiddle to demonstrate the problem.
– Chris Strickland
Mar 22 at 2:45
jsfiddle.net/Ln2gazyv/1 Take a look at this. It contains elements necessary for the document.ready to work. It has four divs and one input. I don't know for sure if #currentStock is an input element or not from your question. Click the button and see what it outputs. Inspect the input element and you can see the innerHTML element is written, but it doesn't seem to be able to be read. Put something in the text box and click the button again. It will output the value. Read this link: stackoverflow.com/questions/20604299/…
– Chris Strickland
Mar 22 at 3:41
It did read the data, but it also did display a textbox that can be edited. I somehow need it to be like it only displays the number like an inventory count.
– SolarPH
Mar 22 at 3:54
I guess what I'm saying is that it's difficult to diagnose your code with what you have given. If you have an input element, you need to set the value. If you are displaying the value in a div or similar, then you want to set the innerHTML, but in either case I don't know why you are trying to assign to cStock from #currentStock when you are writing the data to #currentStock from var currentStock in the first place. Why don't you just use that same variable instead of trying to create a new one?
– Chris Strickland
Mar 22 at 6:34
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%2f55291689%2fcannot-get-the-number-of-var-using-javascript%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It doesn't look to me like #currentStock will have a data attribute, or value attribute (which is for inputs), so of course the js returns undefined. Right now it looks like #currentStock is having the innerHTML set on the document.ready to Current Stocks: 0
You do have an accessible variable, currentStock, which is defined during document.ready. Why aren't you accessing it directly? It will have the numeric value in it already. All you can get from #currentStock is the html you generated on document.ready, and you'd have to parse the number out of it, when it's available in raw form in the js variable currentStock.
I also tried to put it inside a separate script tag, but it behaves the same. I don't know if I made the variable data accessible by the javascript file.
– SolarPH
Mar 22 at 2:25
What I'm saying is that cStocks would be expected to contain undefined, because it's getting assigned the value of document.getElementById('currentStock').data, and there's no such thing unless #currentStock explicitly has a data attribute. Does it? And if so, where is it getting set? There's also no such thing as document.getElementById('currentStock').value unless #currentStock is an input element. Is it? If it is, where is the value getting set, and what is it getting set to? Let me put together a fiddle to demonstrate the problem.
– Chris Strickland
Mar 22 at 2:45
jsfiddle.net/Ln2gazyv/1 Take a look at this. It contains elements necessary for the document.ready to work. It has four divs and one input. I don't know for sure if #currentStock is an input element or not from your question. Click the button and see what it outputs. Inspect the input element and you can see the innerHTML element is written, but it doesn't seem to be able to be read. Put something in the text box and click the button again. It will output the value. Read this link: stackoverflow.com/questions/20604299/…
– Chris Strickland
Mar 22 at 3:41
It did read the data, but it also did display a textbox that can be edited. I somehow need it to be like it only displays the number like an inventory count.
– SolarPH
Mar 22 at 3:54
I guess what I'm saying is that it's difficult to diagnose your code with what you have given. If you have an input element, you need to set the value. If you are displaying the value in a div or similar, then you want to set the innerHTML, but in either case I don't know why you are trying to assign to cStock from #currentStock when you are writing the data to #currentStock from var currentStock in the first place. Why don't you just use that same variable instead of trying to create a new one?
– Chris Strickland
Mar 22 at 6:34
add a comment |
It doesn't look to me like #currentStock will have a data attribute, or value attribute (which is for inputs), so of course the js returns undefined. Right now it looks like #currentStock is having the innerHTML set on the document.ready to Current Stocks: 0
You do have an accessible variable, currentStock, which is defined during document.ready. Why aren't you accessing it directly? It will have the numeric value in it already. All you can get from #currentStock is the html you generated on document.ready, and you'd have to parse the number out of it, when it's available in raw form in the js variable currentStock.
I also tried to put it inside a separate script tag, but it behaves the same. I don't know if I made the variable data accessible by the javascript file.
– SolarPH
Mar 22 at 2:25
What I'm saying is that cStocks would be expected to contain undefined, because it's getting assigned the value of document.getElementById('currentStock').data, and there's no such thing unless #currentStock explicitly has a data attribute. Does it? And if so, where is it getting set? There's also no such thing as document.getElementById('currentStock').value unless #currentStock is an input element. Is it? If it is, where is the value getting set, and what is it getting set to? Let me put together a fiddle to demonstrate the problem.
– Chris Strickland
Mar 22 at 2:45
jsfiddle.net/Ln2gazyv/1 Take a look at this. It contains elements necessary for the document.ready to work. It has four divs and one input. I don't know for sure if #currentStock is an input element or not from your question. Click the button and see what it outputs. Inspect the input element and you can see the innerHTML element is written, but it doesn't seem to be able to be read. Put something in the text box and click the button again. It will output the value. Read this link: stackoverflow.com/questions/20604299/…
– Chris Strickland
Mar 22 at 3:41
It did read the data, but it also did display a textbox that can be edited. I somehow need it to be like it only displays the number like an inventory count.
– SolarPH
Mar 22 at 3:54
I guess what I'm saying is that it's difficult to diagnose your code with what you have given. If you have an input element, you need to set the value. If you are displaying the value in a div or similar, then you want to set the innerHTML, but in either case I don't know why you are trying to assign to cStock from #currentStock when you are writing the data to #currentStock from var currentStock in the first place. Why don't you just use that same variable instead of trying to create a new one?
– Chris Strickland
Mar 22 at 6:34
add a comment |
It doesn't look to me like #currentStock will have a data attribute, or value attribute (which is for inputs), so of course the js returns undefined. Right now it looks like #currentStock is having the innerHTML set on the document.ready to Current Stocks: 0
You do have an accessible variable, currentStock, which is defined during document.ready. Why aren't you accessing it directly? It will have the numeric value in it already. All you can get from #currentStock is the html you generated on document.ready, and you'd have to parse the number out of it, when it's available in raw form in the js variable currentStock.
It doesn't look to me like #currentStock will have a data attribute, or value attribute (which is for inputs), so of course the js returns undefined. Right now it looks like #currentStock is having the innerHTML set on the document.ready to Current Stocks: 0
You do have an accessible variable, currentStock, which is defined during document.ready. Why aren't you accessing it directly? It will have the numeric value in it already. All you can get from #currentStock is the html you generated on document.ready, and you'd have to parse the number out of it, when it's available in raw form in the js variable currentStock.
answered Mar 22 at 2:01
Chris StricklandChris Strickland
520313
520313
I also tried to put it inside a separate script tag, but it behaves the same. I don't know if I made the variable data accessible by the javascript file.
– SolarPH
Mar 22 at 2:25
What I'm saying is that cStocks would be expected to contain undefined, because it's getting assigned the value of document.getElementById('currentStock').data, and there's no such thing unless #currentStock explicitly has a data attribute. Does it? And if so, where is it getting set? There's also no such thing as document.getElementById('currentStock').value unless #currentStock is an input element. Is it? If it is, where is the value getting set, and what is it getting set to? Let me put together a fiddle to demonstrate the problem.
– Chris Strickland
Mar 22 at 2:45
jsfiddle.net/Ln2gazyv/1 Take a look at this. It contains elements necessary for the document.ready to work. It has four divs and one input. I don't know for sure if #currentStock is an input element or not from your question. Click the button and see what it outputs. Inspect the input element and you can see the innerHTML element is written, but it doesn't seem to be able to be read. Put something in the text box and click the button again. It will output the value. Read this link: stackoverflow.com/questions/20604299/…
– Chris Strickland
Mar 22 at 3:41
It did read the data, but it also did display a textbox that can be edited. I somehow need it to be like it only displays the number like an inventory count.
– SolarPH
Mar 22 at 3:54
I guess what I'm saying is that it's difficult to diagnose your code with what you have given. If you have an input element, you need to set the value. If you are displaying the value in a div or similar, then you want to set the innerHTML, but in either case I don't know why you are trying to assign to cStock from #currentStock when you are writing the data to #currentStock from var currentStock in the first place. Why don't you just use that same variable instead of trying to create a new one?
– Chris Strickland
Mar 22 at 6:34
add a comment |
I also tried to put it inside a separate script tag, but it behaves the same. I don't know if I made the variable data accessible by the javascript file.
– SolarPH
Mar 22 at 2:25
What I'm saying is that cStocks would be expected to contain undefined, because it's getting assigned the value of document.getElementById('currentStock').data, and there's no such thing unless #currentStock explicitly has a data attribute. Does it? And if so, where is it getting set? There's also no such thing as document.getElementById('currentStock').value unless #currentStock is an input element. Is it? If it is, where is the value getting set, and what is it getting set to? Let me put together a fiddle to demonstrate the problem.
– Chris Strickland
Mar 22 at 2:45
jsfiddle.net/Ln2gazyv/1 Take a look at this. It contains elements necessary for the document.ready to work. It has four divs and one input. I don't know for sure if #currentStock is an input element or not from your question. Click the button and see what it outputs. Inspect the input element and you can see the innerHTML element is written, but it doesn't seem to be able to be read. Put something in the text box and click the button again. It will output the value. Read this link: stackoverflow.com/questions/20604299/…
– Chris Strickland
Mar 22 at 3:41
It did read the data, but it also did display a textbox that can be edited. I somehow need it to be like it only displays the number like an inventory count.
– SolarPH
Mar 22 at 3:54
I guess what I'm saying is that it's difficult to diagnose your code with what you have given. If you have an input element, you need to set the value. If you are displaying the value in a div or similar, then you want to set the innerHTML, but in either case I don't know why you are trying to assign to cStock from #currentStock when you are writing the data to #currentStock from var currentStock in the first place. Why don't you just use that same variable instead of trying to create a new one?
– Chris Strickland
Mar 22 at 6:34
I also tried to put it inside a separate script tag, but it behaves the same. I don't know if I made the variable data accessible by the javascript file.
– SolarPH
Mar 22 at 2:25
I also tried to put it inside a separate script tag, but it behaves the same. I don't know if I made the variable data accessible by the javascript file.
– SolarPH
Mar 22 at 2:25
What I'm saying is that cStocks would be expected to contain undefined, because it's getting assigned the value of document.getElementById('currentStock').data, and there's no such thing unless #currentStock explicitly has a data attribute. Does it? And if so, where is it getting set? There's also no such thing as document.getElementById('currentStock').value unless #currentStock is an input element. Is it? If it is, where is the value getting set, and what is it getting set to? Let me put together a fiddle to demonstrate the problem.
– Chris Strickland
Mar 22 at 2:45
What I'm saying is that cStocks would be expected to contain undefined, because it's getting assigned the value of document.getElementById('currentStock').data, and there's no such thing unless #currentStock explicitly has a data attribute. Does it? And if so, where is it getting set? There's also no such thing as document.getElementById('currentStock').value unless #currentStock is an input element. Is it? If it is, where is the value getting set, and what is it getting set to? Let me put together a fiddle to demonstrate the problem.
– Chris Strickland
Mar 22 at 2:45
jsfiddle.net/Ln2gazyv/1 Take a look at this. It contains elements necessary for the document.ready to work. It has four divs and one input. I don't know for sure if #currentStock is an input element or not from your question. Click the button and see what it outputs. Inspect the input element and you can see the innerHTML element is written, but it doesn't seem to be able to be read. Put something in the text box and click the button again. It will output the value. Read this link: stackoverflow.com/questions/20604299/…
– Chris Strickland
Mar 22 at 3:41
jsfiddle.net/Ln2gazyv/1 Take a look at this. It contains elements necessary for the document.ready to work. It has four divs and one input. I don't know for sure if #currentStock is an input element or not from your question. Click the button and see what it outputs. Inspect the input element and you can see the innerHTML element is written, but it doesn't seem to be able to be read. Put something in the text box and click the button again. It will output the value. Read this link: stackoverflow.com/questions/20604299/…
– Chris Strickland
Mar 22 at 3:41
It did read the data, but it also did display a textbox that can be edited. I somehow need it to be like it only displays the number like an inventory count.
– SolarPH
Mar 22 at 3:54
It did read the data, but it also did display a textbox that can be edited. I somehow need it to be like it only displays the number like an inventory count.
– SolarPH
Mar 22 at 3:54
I guess what I'm saying is that it's difficult to diagnose your code with what you have given. If you have an input element, you need to set the value. If you are displaying the value in a div or similar, then you want to set the innerHTML, but in either case I don't know why you are trying to assign to cStock from #currentStock when you are writing the data to #currentStock from var currentStock in the first place. Why don't you just use that same variable instead of trying to create a new one?
– Chris Strickland
Mar 22 at 6:34
I guess what I'm saying is that it's difficult to diagnose your code with what you have given. If you have an input element, you need to set the value. If you are displaying the value in a div or similar, then you want to set the innerHTML, but in either case I don't know why you are trying to assign to cStock from #currentStock when you are writing the data to #currentStock from var currentStock in the first place. Why don't you just use that same variable instead of trying to create a new one?
– Chris Strickland
Mar 22 at 6:34
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%2f55291689%2fcannot-get-the-number-of-var-using-javascript%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
1
Please add your entire HTML file.
– Jack Bashford
Mar 22 at 1:42
1
"cannot get the number of var" makes very little sense
– Pointy
Mar 22 at 1:44
1
Assuming it's the variable
cStocksthat comes back as undefined, why would a DOM element have adataproperty? Are you sure you didn't mean to use either jQuery'sdata()orelement.dataset.dataetc?– adeneo
Mar 22 at 1:46
I mean Number Data set in a var container @Pointy
– SolarPH
Mar 22 at 1:48
By the way, forgot to change it back to .value, but same thing happens @adeneo
– SolarPH
Mar 22 at 1:49