Skip to content Skip to sidebar Skip to footer

GetElementById Or ParseInt Not Working?

I am trying to write a simple form on HTML/Javascript where I type in a number, adds one and then displays it. I got it working but it was concatenating the one instead of adding i

Solution 1:

You forgot to extract value from input element:

var salaryString = document.getElementById("grossSalary").value;

Solution 2:

Add .value

 var salaryString = document.getElementById("grossSalary").value;

Solution 3:

You need to get the value, which is missed in your code.

var salaryString = document.getElementById("grossSalary").value;

Solution 4:

The problem is in your javascript where you set the salaryString variable. You need to make sure to collect the value of the element you are selecting. Like so:

var salaryString = document.getElementById("grossSalary").value;

After you do that, your code should behave as expected.


Solution 5:

The getElementById() method returns the element that has the ID attribute with the specified value. So when you try like

var salaryString = document.getElementById("grossSalary");

so here salaryString is a reference to an Element object, or null if an element with the specified ID is not in the document.

If you are looking fro get the value of the corresponding text box then use something like

var salaryString = document.getElementById("grossSalary").value;

Post a Comment for "GetElementById Or ParseInt Not Working?"