html input value is not getting fetched in javascript [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I wrote a simple code to fetch a value from text field and so its summation and display it in the third text field
Correct code
var a = document.getElementById("fNo");
var b = document.getElementById("sNo");
var c = document.getElementById("tNo");
var d = document.getElementById("abc");
d.addEventListener("click", function() {
c.value = Number(a.value) + Number(b.value);
});
But when I obtain value in a like this
a = document.getElementById("fNo").value;
It doesnt work.

You will get a string querying the value.
If the input element is of type "number" you can use:
a = document.getElementById('fNo').valueAsNumber;
otherwise you have to convert the string to a number, before you can do the calculation:
a = Number(document.getElementById('fNo').value);
b = // etc.

Related

how to fix nan in javascript? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 days ago.
Improve this question
I can't show result in table and another code same problem result nan and number for result how to remove word nan
plz help me.
totalIron = (total *374.15)
totalIron2 = totalIron.toLocaleString("en-US", {style:"currency", currency:"SAR"})
totalIron22 = totalIron2
document.getElementById('resultForIron').innerHTML = totalIron22;
function toTotal() {
return +totalIron22 + +`ironjs22` + +cement111 + +`blockjs11`;
};
`totalSecaion22` = (totalIron22 + toTotal());
document.getElementById('result2').innerHTML = `totalSecaion22`;
NaN is returned when you try to do something for which a numeric value is not possible. For example, trying to parse a string that doesn't represent a number or taking the square root of a negative number.
If you want to replace NaN with some other value, you could test the result of your operation to check if that result is NaN. The test would look like this:
let isItANumber = !isNaN(x);
console.log(isItANumber); // prints 'false'
But you can't force the result to be a number.

How do I use concatenated string in a DIV? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I think my concatenating is fine, but my use of it isn't working. Any help would be appreciated. Thanks.
<script>
var str1 = "/images/";
var str2 = "test.jpg";
var res = str1.concat(str2);
</script>
<div class="product-sprite" data-image="res"></div>
DOM element attributes are not evaluated as variables. You need to assign it to the element property.
var res = str1 + str2; // no need to use .concat()
document.querySelector(".product-sprite").dataset.image = res;

Add 2 variables inside another variable [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am trying to create a search variable taking the value of 2 others variables for search results
But I don't manage to get the expected result (title + author). In a sense where the author value is not taking into consideration.
How can I write the following correctly the get both correct values (title + author) in the search variable?
Thank you
let title = document.getElementById('titre-livre').value;
let author = document.getElementById('auteur').value;
let search = title + author;
Remember to separate these values with a space:
let search = [title, author].join(' ');

Remove category from phone number in javascript [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have a phone number in iOS displayed in a list like :
home: (789)654-1281
I want to remove the home or any other category that will attach with the mobile number.I tried replace() in javascript,but it is not working.Please help.
I am developing hybrid application using kony.
Maybe you can try with something like this :
var number = 'home: (789)654-1281';
number = number.split(': ')[1]; // (789)654-1281
Hope it helps.
var input = "home: (789)654-1281"
var position = input.indexOf(': '); // with space
if (position > 0) {
var output = input.substring(position+2); // + 2 is length of ': '
}

How to add var in get value in JavaScript? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
How to add var in get value in JavaScript ?
I have 2 var
var page = $('#demoajax').val();
var name = $("#users").val();
This is mym old code
data:"server=Windows&actionfunction=showData&page="+page,
I want to add var name and value now=date to this line how can I do that ?
First I try this
data:"username="+name+"&server=Windows&actionfunction=showData&page="+page+"&now=date",
But not work.
You appear to have inserted your changes in the middle of the query string. Try this instead.
data:"server=Windows&username="+name+"&actionfunction=showData&page="+page+"&now=date",
Why do you have data:"username="+name+"&server=Windows&actionfunction=showData&page="+page+"&date=now",
switch date and now
Also lose the comma at end if not needed

Categories